@moneybar.online/moneybar 9.0.1 → 9.0.2

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/README.md CHANGED
@@ -1,424 +1,275 @@
1
- # MoneyBar - Complete Integration Guide
2
- ## The NavBar of Monetization
1
+ # MoneyBar
3
2
 
4
- > **Every product has a navbar for navigation. Every product needs a moneybar for monetization.**
3
+ **The navbar that gets you money faster.** Complete backend infrastructure included. Setup in 1 minute.
5
4
 
6
- MoneyBar fixes the 3 critical money-blocking stages that prevent revenue from reaching your bank account, even when your product is good enough. Add usage limiting and premium upgrades to any web app in **3 simple steps**.
7
-
8
- [![npm version](https://badge.fury.io/js/%40moneybar.online%2Fmoneybar.svg)](https://www.npmjs.com/package/@moneybar.online/moneybar)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ MoneyBar handles authentication, payment processing, usage limits, and subscription management - all in one navbar component. No backend coding required.
10
6
 
11
7
  ---
12
8
 
13
- ## 🏗️ Architecture Guidelines
9
+ ## Quick Start (2 Steps)
14
10
 
15
- **Keep your code clean with proper separation:**
11
+ ### Step 1: Copy & Customize Config
16
12
 
17
- ### Recommended File Structure
18
- ```
19
- index.html // Only your custom business functions
20
- moneybar-config.js // All MoneyBar configuration and setup
21
- ```
13
+ Copy `moneybar-config-template.js` to your project and customize these settings:
22
14
 
23
- ### 🚫 Avoid This
24
- - Don't mix MoneyBar configuration directly in HTML files
25
- - Don't put business logic in config files
26
- - Keep concerns separated for maintainability
15
+ ```javascript
16
+ const CONFIG = {
17
+ // ========================================
18
+ // CUSTOMIZABLE SETTINGS
19
+ // ========================================
27
20
 
28
- ### 📋 Template Prompt
29
- When creating MoneyBar projects, follow this structure:
30
- > "HTML should contain only custom business functions. All MoneyBar configuration, initialization, and attachToButton calls should be in a separate config file."
21
+ // Security key - Get yours from Supabase
22
+ // Run: SELECT generate_security_key('my-app', 'yourdomain.com', 'your@email.com', 3)
23
+ security_key: 'sk_...',
31
24
 
32
- ---
25
+ // What are users doing? (shown in UI: "PDF Generations: 2/3")
26
+ actionLabel: 'PDF Generations', // Examples: 'Image Exports', 'Downloads', 'AI Requests'
33
27
 
34
- ## 🚀 Installation & Usage
28
+ // How many free attempts before paywall?
29
+ freeAttemptLimit: 3,
35
30
 
36
- ### Option 1: NPM Install (For projects with bundlers)
37
- ```bash
38
- npm install @moneybar.online/moneybar
39
- ```
31
+ // Payment setup (optional - add later if needed)
32
+ payment: [{
33
+ provider: 'dodo',
34
+ productId: 'pdt_xxx', // Get from Dodo Payments dashboard
35
+ mode: 'test' // 'test' or 'live'
36
+ }],
40
37
 
41
- ```javascript
42
- import { MoneyBar } from '@moneybar.online/moneybar';
38
+ // Feedback form (optional)
39
+ feedback: {
40
+ form: {
41
+ title: 'Quick Feedback',
42
+ description: 'What stopped you from upgrading?',
43
+ option1: 'Too expensive',
44
+ option2: 'Not enough features',
45
+ option3: 'Need more time to evaluate'
46
+ },
47
+ email: [{
48
+ provider: 'resend',
49
+ apiKey: 'your-resend-api-key',
50
+ fromEmail: 'feedback@yourapp.com'
51
+ }]
52
+ },
43
53
 
44
- const moneyBar = new MoneyBar({
45
- actionFunction: 'generatePDF',
46
- appId: 'my-pdf-app',
47
- freeAttemptLimit: 3,
48
- supabase: {
49
- url: 'your-supabase-url',
50
- anonKey: 'your-anon-key'
54
+ // UI Theme (optional)
55
+ theme: {
56
+ name: 'emerald', // DaisyUI theme name
57
+ primaryColor: '#059669'
51
58
  },
52
- payment: [{
53
- provider: 'dodo',
54
- productId: 'your-product-id',
55
- mode: 'test'
56
- }]
57
- });
58
59
 
59
- moneyBar.attachToButton('#action-btn', generatePDF);
60
+ // Title bar (optional)
61
+ titleBar: {
62
+ title: '🚀 My App',
63
+ links: [
64
+ { text: 'Features', url: '#features', target: '_self' },
65
+ { text: 'Pricing', url: '#pricing', target: '_self' }
66
+ ]
67
+ },
60
68
 
61
- function generatePDF(userContext) {
62
- if (userContext.isPremium) {
63
- alert('Premium PDF generated with all features!');
64
- } else {
65
- alert(`Basic PDF generated! ${userContext.remaining} downloads remaining`);
69
+ // ⚠️ DO NOT MODIFY - Required for MoneyBar to work
70
+ supabase: {
71
+ url: 'https://qhlzdkwcrrjjcqvupyaa.supabase.co',
72
+ anonKey: 'eyJ...'
66
73
  }
67
- }
74
+ };
68
75
  ```
69
76
 
70
- ### Option 2: CDN (Recommended for HTML projects)
77
+ ---
78
+
79
+ ### Step 2: Add to HTML & Attach to Buttons
80
+
81
+ Add these scripts to your HTML:
71
82
 
72
- **index.html** (Business logic only):
73
83
  ```html
74
84
  <!DOCTYPE html>
75
85
  <html>
86
+ <head>
87
+ <title>My App</title>
88
+ </head>
76
89
  <body>
77
- <button id="action-btn">Try Action</button>
90
+ <!-- Your app content -->
91
+ <button id="my-custom-btn">Generate PDF</button>
78
92
 
79
- <!-- Include MoneyBar configuration -->
80
- <script type="module" src="moneybar-config.js"></script>
93
+ <!-- Step 2a: Load MoneyBar config -->
94
+ <script type="module" src="moneybar-config-template.js"></script>
81
95
 
82
- <!-- Your business logic only -->
83
- <script>
84
- function myAction(userContext) {
96
+ <!-- Step 2b: Attach to your buttons -->
97
+ <script type="module">
98
+ // Access the MoneyBar instance
99
+ window.moneyBar.attachToButton('#my-custom-btn', (userContext) => {
100
+
101
+ // Check if user is premium
85
102
  if (userContext.isPremium) {
86
- alert('Premium features unlocked!');
103
+ // ✅ Premium user - no limits!
104
+ generatePDF(); // Your custom function
105
+
87
106
  } else {
88
- alert(`Free trial: ${userContext.remaining} uses left`);
107
+ // Free user - show remaining attempts
108
+ alert(`Free user. ${userContext.remaining} attempts remaining`);
109
+
110
+ if (userContext.remaining > 0) {
111
+ generatePDF(); // Your custom function
112
+ }
89
113
  }
114
+ });
115
+
116
+ // Your custom function
117
+ function generatePDF() {
118
+ console.log('Generating PDF...');
119
+ // Your PDF generation logic here
90
120
  }
91
121
  </script>
92
122
  </body>
93
123
  </html>
94
124
  ```
95
125
 
96
- **moneybar-config.js** (MoneyBar configuration):
97
- ```javascript
98
- import { MoneyBar } from 'https://cdn.jsdelivr.net/npm/@moneybar.online/moneybar@latest/dist/index.bundle.js';
99
-
100
- const moneyBar = new MoneyBar({
101
- actionFunction: 'myAction',
102
- appId: 'my-app',
103
- freeAttemptLimit: 3,
104
- supabase: {
105
- url: 'your-supabase-url',
106
- anonKey: 'your-anon-key'
107
- },
108
- payment: [{
109
- provider: 'dodo',
110
- productId: 'your-product-id',
111
- mode: 'test'
112
- }]
113
- });
114
-
115
- moneyBar.attachToButton('#action-btn', myAction);
116
- ```
126
+ ---
117
127
 
118
- ### Quick Start Template
119
- Copy `moneybar-config-template.js` and `example-template.html` from this package for a ready-to-use template.
128
+ ## Understanding UserContext
120
129
 
121
- ## 🚀 Quick Start (2 minutes)
130
+ When you attach to a button, you get a `userContext` object with all user info:
122
131
 
123
- ### Files You Need:
124
- 1. **`example-template.html`** - Working demo with all 3 use cases
125
- 2. **`moneybar-config-template.js`** - Comprehensive configuration with 3 problem-focused examples
132
+ ```javascript
133
+ window.moneyBar.attachToButton('#my-btn', (userContext) => {
126
134
 
127
- ### Try It Now:
128
- ```bash
129
- # After npm install
130
- open example-template.html
131
- ```
135
+ // Premium status
136
+ userContext.isPremium // true/false - Does user have premium access?
137
+ userContext.isAuthenticated // true/false - Is user signed in?
132
138
 
133
- Then edit line 157 in `moneybar-config-template.js` to switch between use cases!
139
+ // Usage limits
140
+ userContext.currentCount // Number - How many times user has used the feature
141
+ userContext.remaining // Number - Remaining free attempts
142
+ userContext.limit // Number - Total free attempt limit
134
143
 
135
- ---
144
+ // User info
145
+ userContext.email // String - User's email (if signed in)
146
+ userContext.name // String - User's name (if available)
136
147
 
137
- ## 📱 The 3 Money-Blocking Problems MoneyBar Solves
138
-
139
- ### Problem #1: "Forced Sign-In Before Value"
140
- **Revenue Impact: 40-60% boost**
141
- - **What Kills Revenue:** Users bounce before seeing your product works
142
- - **MoneyBar Solution:** Value-first trials with 3 free attempts
143
- - 🎯 **Perfect for:** PDF generators, image tools, converters
144
- - 🎨 **Theme:** Emerald (trustworthy, fresh)
145
- - **Config:** `VALUE_FIRST_CONFIG` in template
146
-
147
- ### Problem #2: "Silent Drop-Off"
148
- **Revenue Impact: 20-30% boost**
149
- - ❌ **What Kills Revenue:** Users try but don't buy - you don't know why
150
- - ✅ **MoneyBar Solution:** Exit feedback capture at cancel moment
151
- - 🎯 **Perfect for:** SaaS trials, B2B tools, complex products
152
- - 🎨 **Theme:** Corporate (professional B2B)
153
- - **Config:** `FEEDBACK_INTELLIGENCE_CONFIG` in template
154
-
155
- ### Problem #3: "Broken Money Flow"
156
- **Revenue Impact: 25-40% boost**
157
- - ❌ **What Kills Revenue:** Complex payments and broken sessions
158
- - ✅ **MoneyBar Solution:** Seamless Google Auth + instant payments
159
- - 🎯 **Perfect for:** Templates, premium features, instant upgrades
160
- - 🎨 **Theme:** Dark (modern, premium)
161
- - **Config:** `INSTANT_PAYMENT_CONFIG` in template
162
-
163
- ## 🔧 How to Use
164
-
165
- ### Step 1: Choose Your Use Case
166
- Edit line 157 in `moneybar-config-template.js`:
148
+ // Subscription details (for premium users)
149
+ userContext.subscriptionType // 'one-time', 'monthly', 'quarterly', 'yearly'
150
+ userContext.subscriptionExpiresAt // ISO date string
151
+ userContext.subscriptionDaysRemaining // Number - Days until subscription expires
152
+ userContext.isSubscriptionActive // true/false - Is subscription active?
153
+ userContext.customerId // String - Customer ID for portal access
167
154
 
168
- ```javascript
169
- // Pick one:
170
- window.APP_CONFIG = VALUE_FIRST_CONFIG; // PDF/Image/Converter tools
171
- window.APP_CONFIG = FEEDBACK_INTELLIGENCE_CONFIG; // SaaS/B2B products
172
- window.APP_CONFIG = INSTANT_PAYMENT_CONFIG; // Templates/Premium features
173
- ```
174
-
175
- ### Step 2: Update Credentials (REQUIRED!)
176
- ⚠️ **Before testing, you MUST replace these placeholder values or you'll get errors:**
177
-
178
- ```javascript
179
- supabase: {
180
- url: 'https://your-project.supabase.co', // ✅ Replace with your Supabase project URL
181
- anonKey: 'your-anon-key' // ✅ Replace with your Supabase anon key
182
- },
183
- payment: [{
184
- provider: 'dodo', // ✅ Payment provider
185
- productId: 'your-product-id', // ✅ Replace with your DodoPayments product ID
186
- mode: 'test' // ✅ Set to 'test' or 'live'
187
- }]
155
+ });
188
156
  ```
189
157
 
190
- **🚨 Common Error:** If you get "Cannot read properties of null (reading 'AuthClient')" error:
191
- - ❌ You haven't updated the Supabase credentials above
192
- - ✅ Replace ALL placeholder values with your actual credentials
193
-
194
- ### Step 3: Test the Demo
195
- Open `example-template.html` in your browser and try the button!
196
-
197
158
  ---
198
159
 
199
- ## 🎯 Advanced Features
160
+ ## Common Patterns
200
161
 
201
- ### User Context for Personalization
202
- Access complete user information in your functions:
162
+ ### Pattern 1: Premium vs Free
203
163
 
204
164
  ```javascript
205
- function myAction(userContext) {
206
- console.log({
207
- isPremium: userContext.isPremium, // Boolean
208
- email: userContext.email, // String
209
- name: userContext.name, // String
210
- currentCount: userContext.currentCount, // Number
211
- remaining: userContext.remaining, // Number
212
- isAuthenticated: userContext.isAuthenticated
213
- });
214
-
215
- // Dynamic features based on user status
165
+ window.moneyBar.attachToButton('#export-btn', (userContext) => {
216
166
  if (userContext.isPremium) {
217
- removeWatermark();
167
+ // Full access
168
+ exportHighQuality();
218
169
  } else {
219
- addWatermark();
170
+ // Limited access
171
+ exportLowQuality();
220
172
  }
221
- }
173
+ });
222
174
  ```
223
175
 
176
+ ### Pattern 2: Check Remaining Attempts
224
177
 
225
- ### Feedback Collection Configuration
226
178
  ```javascript
227
- const moneyBar = new MoneyBar({
228
- // ... other config
229
- feedback: {
230
- form: {
231
- title: 'Quick Feedback',
232
- description: 'What stopped you from upgrading?',
233
- option1: 'Too expensive',
234
- option2: 'Need more features',
235
- option3: 'Just testing'
236
- },
237
- email: [
238
- {
239
- provider: 'resend',
240
- apiKey: 'your-resend-api-key',
241
- fromEmail: 'feedback@yourapp.com'
242
- }
243
- // Future providers can be added here:
244
- // {
245
- // provider: 'sendgrid',
246
- // apiKey: 'your-sendgrid-api-key',
247
- // fromEmail: 'feedback@yourapp.com'
248
- // }
249
- ]
179
+ window.moneyBar.attachToButton('#convert-btn', (userContext) => {
180
+ if (userContext.isPremium) {
181
+ convert();
182
+ } else if (userContext.remaining > 0) {
183
+ convert();
184
+ console.log(`${userContext.remaining} attempts left`);
185
+ } else {
186
+ console.log('No attempts remaining - upgrade required');
250
187
  }
251
188
  });
252
189
  ```
253
190
 
254
- ---
255
-
256
- ## 🎨 UI Themes & Customization
257
-
258
- MoneyBar includes 29 beautiful DaisyUI themes:
191
+ ### Pattern 3: Multiple Buttons
259
192
 
260
193
  ```javascript
261
- const moneyBar = new MoneyBar({
262
- // ... other config
263
- theme: {
264
- name: 'dark', // or 'cupcake', 'emerald', 'corporate', etc.
265
- primaryColor: '#059669'
266
- },
267
- titleBar: {
268
- title: 'My App',
269
- links: [
270
- { text: 'Home', url: '/', target: '_self' },
271
- { text: 'About', url: '/about', target: '_self' }
272
- ]
194
+ // Attach to multiple buttons with the same logic
195
+ window.moneyBar.attachToButton('#btn1', handleAction);
196
+ window.moneyBar.attachToButton('#btn2', handleAction);
197
+ window.moneyBar.attachToButton('#btn3', handleAction);
198
+
199
+ function handleAction(userContext) {
200
+ if (userContext.isPremium) {
201
+ performAction();
273
202
  }
274
- });
203
+ }
275
204
  ```
276
205
 
277
- ---
278
-
279
- ## 📊 Complete Configuration Reference
206
+ ### Pattern 4: Different Actions per Button
280
207
 
281
- ### Core Configuration (Required)
282
208
  ```javascript
283
- const moneyBar = new MoneyBar({
284
- // Core required config
285
- appId: 'my-app', // Unique identifier for your app
286
- freeAttemptLimit: 3, // Free attempts before paywall
287
-
288
- // Supabase configuration (required)
289
- supabase: {
290
- url: 'https://xyz.supabase.co', // Your Supabase project URL
291
- anonKey: 'your-anon-key' // Public anon key from Supabase
292
- },
293
-
294
- // Payment configuration (required)
295
- payment: [{
296
- provider: 'dodo', // Payment provider
297
- productId: 'prod_xyz', // DodoPayments product ID
298
- mode: 'test' // 'test' or 'live'
299
- }]
209
+ // Button 1: Export
210
+ window.moneyBar.attachToButton('#export-btn', (ctx) => {
211
+ if (ctx.isPremium) exportPDF();
300
212
  });
301
- ```
302
-
303
- ### 🎨 Available Themes (29 Options)
304
-
305
- **Light Themes:**
306
- - `light` - Clean white theme
307
- - `cupcake` - Soft pink theme
308
- - `bumblebee` - Warm yellow theme
309
- - `emerald` - Fresh green theme
310
- - `corporate` - Professional blue
311
- - `garden` - Nature green
312
- - `lofi` - Minimalist gray
313
- - `pastel` - Soft purple theme
314
- - `fantasy` - Magical pink theme
315
- - `wireframe` - Minimal outline style
316
- - `cmyk` - Print-inspired colors
317
- - `autumn` - Warm orange theme
318
- - `business` - Clean corporate
319
- - `acid` - Bright lime theme
320
- - `lemonade` - Citrus yellow
321
- - `winter` - Cool blue theme
322
-
323
- **Dark Themes:**
324
- - `dark` - Classic dark mode
325
- - `synthwave` - Retro 80s neon
326
- - `retro` - Vintage brown theme
327
- - `cyberpunk` - Futuristic neon
328
- - `valentine` - Deep pink theme
329
- - `halloween` - Orange & purple
330
- - `forest` - Deep forest green
331
- - `aqua` - Ocean blue theme
332
- - `luxury` - Gold & purple
333
- - `dracula` - Purple vampire theme
334
- - `night` - Deep blue dark
335
- - `coffee` - Rich brown theme
336
- - `black` - Pure dark theme
337
-
338
- ### 👤 User Context Properties
339
-
340
- All user information available in your functions:
341
213
 
342
- ```javascript
343
- function myAction(userContext) {
344
- // Available properties:
345
- userContext.isPremium // Boolean: Premium vs Free user
346
- userContext.isAuthenticated // Boolean: Signed in status
347
- userContext.email // String: User's email (if signed in)
348
- userContext.name // String: User's display name (if available)
349
- userContext.currentCount // Number: Actions taken so far
350
- userContext.remaining // Number: Free actions remaining
351
- userContext.limit // Number: Maximum free actions allowed
352
- userContext.user // Object: Full Supabase user object
353
- }
214
+ // Button 2: Convert
215
+ window.moneyBar.attachToButton('#convert-btn', (ctx) => {
216
+ if (ctx.isPremium) convertImage();
217
+ });
354
218
  ```
355
219
 
356
220
  ---
357
221
 
358
- ## 🔧 Backend Setup
222
+ ## What MoneyBar Handles Automatically
359
223
 
360
- ### Supabase Setup
361
- 1. Create a Supabase project
362
- 2. Enable Google OAuth
363
- 3. Set up edge functions for payment verification
364
-
365
- ### Payment Integration
366
- MoneyBar supports DodoPayments for seamless checkout:
367
-
368
- ```javascript
369
- payment: [{
370
- provider: 'dodo',
371
- productId: 'your-dodo-product-id',
372
- mode: 'test' // or 'live'
373
- }]
374
- ```
224
+ **Authentication** - Google sign-in (more providers coming)
225
+ **Usage Tracking** - Counts attempts per user per app
226
+ **Payment Flow** - Checkout, webhooks, confirmation
227
+ **Subscription Management** - Auto-renewal, expiry, cancellation
228
+ ✅ **Customer Portal** - Self-service subscription management
229
+ **Caching** - 24h cache for premium status, 60s for usage counts
230
+ **Multi-app Support** - Same user, different apps, separate limits
375
231
 
376
232
  ---
377
233
 
378
- ## 🚀 Why MoneyBar?
379
-
380
- **For Indie Hackers:**
381
- - ✅ Turn trial users into paying customers
382
- - ✅ Understand why users don't convert
383
- - ✅ Remove friction from payment flow
384
- - ✅ Focus on product, not payment infrastructure
234
+ ## Configuration Reference
385
235
 
386
- **Technical Benefits:**
387
- - ✅ Zero-config auto-initialization
388
- -TypeScript support with full type safety
389
- -User context for personalized experiences
390
- -Built-in UI themes and components
391
- - Server-side tracking (incognito-proof)
392
-
393
- **Revenue Benefits:**
394
- - 40-60% more trial conversions (value-first)
395
- -20-30% better conversion through feedback insights
396
- - ✅ 25-40% higher payment completion rates
236
+ | Setting | Required | Purpose | Example |
237
+ |---------|----------|---------|---------|
238
+ | `security_key` | Yes | App identifier + auth | `'sk_...'` |
239
+ | `actionLabel` | Yes | What users are doing | `'PDF Generations'` |
240
+ | `freeAttemptLimit` | Yes | Free attempts before paywall | `3` |
241
+ | `payment` | Optional | Payment provider config | Dodo Payments |
242
+ | `feedback` | ⬜ Optional | Collect user feedback | Email to you |
243
+ | `theme` | ⬜ Optional | Customize colors | DaisyUI themes |
244
+ | `titleBar` | Optional | Navbar title & links | Your branding |
245
+ | `supabase` | Yes | Backend (DO NOT CHANGE) | Pre-configured |
397
246
 
398
247
  ---
399
248
 
400
- ## 📞 Support & Community
401
-
402
- - **GitHub:** [ravi-cloudworks/moneybar](https://github.com/ravi-cloudworks/moneybar)
403
- - **Website:** [moneybar.online](https://moneybar.online)
404
- - **Issues:** [GitHub Issues](https://github.com/ravi-cloudworks/moneybar/issues)
249
+ ## Getting Your Security Key
405
250
 
406
- ---
251
+ Run this SQL in Supabase SQL Editor:
407
252
 
408
- ## 🎯 Next Steps
253
+ ```sql
254
+ SELECT generate_security_key(
255
+ 'my-app-name', -- Your app identifier
256
+ 'yourdomain.com', -- Your domain
257
+ 'your@email.com', -- Your email
258
+ 3 -- Free attempt limit
259
+ );
260
+ ```
409
261
 
410
- 1. **Try the examples:** Start with [`value-first-demo.html`](examples/value-first-demo.html)
411
- 2. **Copy the config:** Use [`minimum-config.js`](examples/minimum-config.js) as template
412
- 3. **Add your business logic:** Replace the demo function with your code
413
- 4. **Configure feedback:** Set up exit feedback to understand user behavior
414
- 5. **Launch and iterate:** Use feedback data to improve conversion
262
+ Copy the returned `sk_...` key into your config.
415
263
 
416
- **MoneyBar: Because every product needs a navbar for navigation and a moneybar for monetization.** 💰
264
+ ---
417
265
 
418
- ## 📄 License
266
+ ## Support
419
267
 
420
- MIT - Use in any project, commercial or personal.
268
+ - **Issues**: [GitHub Issues](https://github.com/ravi-cloudworks/moneybar/issues)
269
+ - **Docs**: [moneybar.online](https://moneybar.online)
421
270
 
422
271
  ---
423
272
 
424
- **⭐ Star on GitHub if this helped you build better freemium apps!**
273
+ ## License
274
+
275
+ MIT