@withvlibe/base-sdk 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/README.md +369 -0
- package/dist/VlibeBaseAuth-ChuzgzDl.d.mts +562 -0
- package/dist/VlibeBaseAuth-ChuzgzDl.d.ts +562 -0
- package/dist/index.d.mts +158 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +702 -0
- package/dist/index.mjs +673 -0
- package/dist/react.d.mts +96 -0
- package/dist/react.d.ts +96 -0
- package/dist/react.js +273 -0
- package/dist/react.mjs +245 -0
- package/package.json +73 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for @withvlibe/base-sdk
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* App category for Vlibe Base apps
|
|
6
|
+
*/
|
|
7
|
+
type AppCategory = 'website' | 'saas' | 'ecommerce';
|
|
8
|
+
/**
|
|
9
|
+
* Vlibe Base plan type
|
|
10
|
+
*/
|
|
11
|
+
type BasePlan = 'free' | 'premium';
|
|
12
|
+
/**
|
|
13
|
+
* Main configuration for Vlibe Base SDK
|
|
14
|
+
*/
|
|
15
|
+
interface VlibeBaseConfig {
|
|
16
|
+
appId: string;
|
|
17
|
+
appSecret: string;
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
category?: AppCategory;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Database client configuration
|
|
23
|
+
*/
|
|
24
|
+
interface DatabaseConfig {
|
|
25
|
+
projectId: string;
|
|
26
|
+
databaseToken: string;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
supabaseUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Authentication configuration
|
|
32
|
+
*/
|
|
33
|
+
interface AuthConfig {
|
|
34
|
+
appId: string;
|
|
35
|
+
appSecret: string;
|
|
36
|
+
baseUrl?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Payments configuration
|
|
40
|
+
*/
|
|
41
|
+
interface PaymentsConfig {
|
|
42
|
+
appId: string;
|
|
43
|
+
appSecret: string;
|
|
44
|
+
baseUrl?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Supported column types for table schemas
|
|
48
|
+
*/
|
|
49
|
+
type ColumnType = 'string' | 'number' | 'boolean' | 'json' | 'datetime';
|
|
50
|
+
/**
|
|
51
|
+
* Column definition for table creation
|
|
52
|
+
*/
|
|
53
|
+
interface TableColumn {
|
|
54
|
+
name: string;
|
|
55
|
+
type: ColumnType;
|
|
56
|
+
required?: boolean;
|
|
57
|
+
unique?: boolean;
|
|
58
|
+
default?: unknown;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Table schema for creation
|
|
62
|
+
*/
|
|
63
|
+
interface TableSchema {
|
|
64
|
+
columns: TableColumn[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Table information from the database
|
|
68
|
+
*/
|
|
69
|
+
interface TableInfo {
|
|
70
|
+
name: string;
|
|
71
|
+
columns: TableColumn[];
|
|
72
|
+
rowCount: number;
|
|
73
|
+
createdAt: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Query options for database operations
|
|
77
|
+
*/
|
|
78
|
+
interface QueryOptions {
|
|
79
|
+
limit?: number;
|
|
80
|
+
offset?: number;
|
|
81
|
+
orderBy?: string;
|
|
82
|
+
orderDirection?: 'asc' | 'desc';
|
|
83
|
+
where?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Base record type with common fields
|
|
87
|
+
*/
|
|
88
|
+
interface BaseRecord {
|
|
89
|
+
id: string;
|
|
90
|
+
created_at: string;
|
|
91
|
+
updated_at: string;
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Real-time subscription payload
|
|
96
|
+
*/
|
|
97
|
+
interface RealtimePayload<T = BaseRecord> {
|
|
98
|
+
eventType: 'INSERT' | 'UPDATE' | 'DELETE';
|
|
99
|
+
new: T | null;
|
|
100
|
+
old: T | null;
|
|
101
|
+
table: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Subscription handle for cleanup
|
|
105
|
+
*/
|
|
106
|
+
interface Subscription {
|
|
107
|
+
unsubscribe: () => void;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Vlibe user object returned from authentication
|
|
111
|
+
*/
|
|
112
|
+
interface VlibeUser {
|
|
113
|
+
id: string;
|
|
114
|
+
email: string;
|
|
115
|
+
name: string | null;
|
|
116
|
+
avatarUrl: string | null;
|
|
117
|
+
subscriptionType: 'platform' | 'individual' | null;
|
|
118
|
+
appAccess?: {
|
|
119
|
+
tier: string | null;
|
|
120
|
+
features: string[];
|
|
121
|
+
} | null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Response from session verification
|
|
125
|
+
*/
|
|
126
|
+
interface VerifyResponse {
|
|
127
|
+
valid: boolean;
|
|
128
|
+
user?: VlibeUser;
|
|
129
|
+
error?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Authentication session
|
|
133
|
+
*/
|
|
134
|
+
interface AuthSession {
|
|
135
|
+
user: VlibeUser;
|
|
136
|
+
token: string;
|
|
137
|
+
expiresAt: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Options for creating a checkout session
|
|
141
|
+
*/
|
|
142
|
+
interface CheckoutOptions {
|
|
143
|
+
/** Amount in cents (e.g., 1999 for $19.99) */
|
|
144
|
+
amount: number;
|
|
145
|
+
/** Currency code (default: 'usd') */
|
|
146
|
+
currency?: string;
|
|
147
|
+
/** User ID to associate with the payment */
|
|
148
|
+
userId?: string;
|
|
149
|
+
/** User email for receipt */
|
|
150
|
+
userEmail?: string;
|
|
151
|
+
/** Description of the payment */
|
|
152
|
+
description?: string;
|
|
153
|
+
/** Metadata to attach to the payment */
|
|
154
|
+
metadata?: Record<string, string>;
|
|
155
|
+
/** URL to redirect on success */
|
|
156
|
+
successUrl: string;
|
|
157
|
+
/** URL to redirect on cancel */
|
|
158
|
+
cancelUrl: string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Checkout session response
|
|
162
|
+
*/
|
|
163
|
+
interface CheckoutSession {
|
|
164
|
+
id: string;
|
|
165
|
+
url: string;
|
|
166
|
+
amount: number;
|
|
167
|
+
currency: string;
|
|
168
|
+
status: string;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Transaction record
|
|
172
|
+
*/
|
|
173
|
+
interface Transaction {
|
|
174
|
+
id: string;
|
|
175
|
+
amount: number;
|
|
176
|
+
vlibeFee: number;
|
|
177
|
+
netAmount: number;
|
|
178
|
+
currency: string;
|
|
179
|
+
status: 'pending' | 'succeeded' | 'failed' | 'refunded';
|
|
180
|
+
stripeId?: string;
|
|
181
|
+
userId?: string;
|
|
182
|
+
metadata?: Record<string, string>;
|
|
183
|
+
createdAt: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Refund options
|
|
187
|
+
*/
|
|
188
|
+
interface RefundOptions {
|
|
189
|
+
transactionId: string;
|
|
190
|
+
amount?: number;
|
|
191
|
+
reason?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Stripe Connect status
|
|
195
|
+
*/
|
|
196
|
+
interface ConnectStatus {
|
|
197
|
+
connected: boolean;
|
|
198
|
+
accountId?: string;
|
|
199
|
+
chargesEnabled?: boolean;
|
|
200
|
+
payoutsEnabled?: boolean;
|
|
201
|
+
}
|
|
202
|
+
interface Page {
|
|
203
|
+
id: string;
|
|
204
|
+
title: string;
|
|
205
|
+
slug: string;
|
|
206
|
+
content: string;
|
|
207
|
+
metaTitle?: string;
|
|
208
|
+
metaDescription?: string;
|
|
209
|
+
isPublished: boolean;
|
|
210
|
+
createdAt: string;
|
|
211
|
+
updatedAt: string;
|
|
212
|
+
}
|
|
213
|
+
interface Media {
|
|
214
|
+
id: string;
|
|
215
|
+
filename: string;
|
|
216
|
+
url: string;
|
|
217
|
+
mimeType: string;
|
|
218
|
+
size: number;
|
|
219
|
+
alt?: string;
|
|
220
|
+
createdAt: string;
|
|
221
|
+
}
|
|
222
|
+
interface FeatureFlag {
|
|
223
|
+
id: string;
|
|
224
|
+
key: string;
|
|
225
|
+
name: string;
|
|
226
|
+
description?: string;
|
|
227
|
+
isEnabled: boolean;
|
|
228
|
+
tier?: string;
|
|
229
|
+
createdAt: string;
|
|
230
|
+
}
|
|
231
|
+
interface UsageMetric {
|
|
232
|
+
id: string;
|
|
233
|
+
userId: string;
|
|
234
|
+
metricType: string;
|
|
235
|
+
value: number;
|
|
236
|
+
period: string;
|
|
237
|
+
createdAt: string;
|
|
238
|
+
}
|
|
239
|
+
interface Product {
|
|
240
|
+
id: string;
|
|
241
|
+
name: string;
|
|
242
|
+
description?: string;
|
|
243
|
+
sku?: string;
|
|
244
|
+
price: number;
|
|
245
|
+
currency: string;
|
|
246
|
+
images: string[];
|
|
247
|
+
stock: number;
|
|
248
|
+
isActive: boolean;
|
|
249
|
+
category?: string;
|
|
250
|
+
createdAt: string;
|
|
251
|
+
updatedAt: string;
|
|
252
|
+
}
|
|
253
|
+
interface Order {
|
|
254
|
+
id: string;
|
|
255
|
+
userId: string;
|
|
256
|
+
status: 'pending' | 'processing' | 'shipped' | 'delivered' | 'cancelled';
|
|
257
|
+
items: OrderItem[];
|
|
258
|
+
subtotal: number;
|
|
259
|
+
tax: number;
|
|
260
|
+
total: number;
|
|
261
|
+
shippingAddress?: Address;
|
|
262
|
+
createdAt: string;
|
|
263
|
+
}
|
|
264
|
+
interface OrderItem {
|
|
265
|
+
productId: string;
|
|
266
|
+
name: string;
|
|
267
|
+
quantity: number;
|
|
268
|
+
price: number;
|
|
269
|
+
}
|
|
270
|
+
interface Address {
|
|
271
|
+
line1: string;
|
|
272
|
+
line2?: string;
|
|
273
|
+
city: string;
|
|
274
|
+
state: string;
|
|
275
|
+
postalCode: string;
|
|
276
|
+
country: string;
|
|
277
|
+
}
|
|
278
|
+
interface CartItem {
|
|
279
|
+
productId: string;
|
|
280
|
+
quantity: number;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Standard API response
|
|
284
|
+
*/
|
|
285
|
+
interface ApiResponse<T = unknown> {
|
|
286
|
+
success: boolean;
|
|
287
|
+
data?: T;
|
|
288
|
+
error?: string;
|
|
289
|
+
message?: string;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Paginated API response
|
|
293
|
+
*/
|
|
294
|
+
interface PaginatedResponse<T = unknown> {
|
|
295
|
+
success: boolean;
|
|
296
|
+
data: T[];
|
|
297
|
+
total: number;
|
|
298
|
+
page: number;
|
|
299
|
+
limit: number;
|
|
300
|
+
hasMore: boolean;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Options for useCollection hook
|
|
304
|
+
*/
|
|
305
|
+
interface UseCollectionOptions {
|
|
306
|
+
limit?: number;
|
|
307
|
+
orderBy?: string;
|
|
308
|
+
orderDirection?: 'asc' | 'desc';
|
|
309
|
+
where?: Record<string, unknown>;
|
|
310
|
+
realtime?: boolean;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Return type for useCollection hook
|
|
314
|
+
*/
|
|
315
|
+
interface UseCollectionReturn<T = BaseRecord> {
|
|
316
|
+
data: T[];
|
|
317
|
+
loading: boolean;
|
|
318
|
+
error: Error | null;
|
|
319
|
+
refresh: () => Promise<void>;
|
|
320
|
+
insert: (doc: Partial<T>) => Promise<T | null>;
|
|
321
|
+
update: (id: string, updates: Partial<T>) => Promise<T | null>;
|
|
322
|
+
remove: (id: string) => Promise<boolean>;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Return type for useKV hook
|
|
326
|
+
*/
|
|
327
|
+
interface UseKVReturn<T = unknown> {
|
|
328
|
+
data: T | null;
|
|
329
|
+
loading: boolean;
|
|
330
|
+
error: Error | null;
|
|
331
|
+
set: (value: T) => Promise<void>;
|
|
332
|
+
refresh: () => Promise<void>;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Return type for useAuth hook
|
|
336
|
+
*/
|
|
337
|
+
interface UseAuthReturn {
|
|
338
|
+
user: VlibeUser | null;
|
|
339
|
+
loading: boolean;
|
|
340
|
+
error: Error | null;
|
|
341
|
+
login: (redirectPath?: string) => void;
|
|
342
|
+
logout: (redirectPath?: string) => void;
|
|
343
|
+
hasFeature: (feature: string) => boolean;
|
|
344
|
+
hasSubscription: () => boolean;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Return type for usePayments hook
|
|
348
|
+
*/
|
|
349
|
+
interface UsePaymentsReturn {
|
|
350
|
+
loading: boolean;
|
|
351
|
+
error: Error | null;
|
|
352
|
+
createCheckout: (options: CheckoutOptions) => Promise<string | null>;
|
|
353
|
+
transactions: Transaction[];
|
|
354
|
+
loadTransactions: () => Promise<void>;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* VlibeBaseDatabase - Database client for Vlibe Base Apps
|
|
359
|
+
*
|
|
360
|
+
* Provides access to the Vlibe managed database for Base apps.
|
|
361
|
+
* Supports CRUD operations, real-time subscriptions, and key-value storage.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```typescript
|
|
365
|
+
* import { VlibeBaseDatabase } from '@withvlibe/base-sdk';
|
|
366
|
+
*
|
|
367
|
+
* const db = new VlibeBaseDatabase({
|
|
368
|
+
* projectId: process.env.VLIBE_PROJECT_ID!,
|
|
369
|
+
* databaseToken: process.env.VLIBE_DB_TOKEN!,
|
|
370
|
+
* });
|
|
371
|
+
*
|
|
372
|
+
* // CRUD operations
|
|
373
|
+
* const doc = await db.insert('documents', { title: 'Hello', content: 'World' });
|
|
374
|
+
* const docs = await db.query('documents');
|
|
375
|
+
* await db.update('documents', doc.id, { title: 'Updated' });
|
|
376
|
+
* await db.delete('documents', doc.id);
|
|
377
|
+
*
|
|
378
|
+
* // Key-value store
|
|
379
|
+
* await db.setKV('settings', { theme: 'dark' });
|
|
380
|
+
* const settings = await db.getKV('settings');
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
declare class VlibeBaseDatabase {
|
|
385
|
+
private projectId;
|
|
386
|
+
private databaseToken;
|
|
387
|
+
private baseUrl;
|
|
388
|
+
private supabaseUrl;
|
|
389
|
+
private supabase;
|
|
390
|
+
private subscriptions;
|
|
391
|
+
/**
|
|
392
|
+
* Create a new VlibeBaseDatabase instance
|
|
393
|
+
*
|
|
394
|
+
* @param config - Database configuration
|
|
395
|
+
* @throws Error if projectId or databaseToken is missing
|
|
396
|
+
*/
|
|
397
|
+
constructor(config: DatabaseConfig);
|
|
398
|
+
/**
|
|
399
|
+
* Initialize Supabase client for real-time subscriptions
|
|
400
|
+
*/
|
|
401
|
+
private initSupabase;
|
|
402
|
+
/**
|
|
403
|
+
* Make an authenticated API request
|
|
404
|
+
*/
|
|
405
|
+
private apiRequest;
|
|
406
|
+
/**
|
|
407
|
+
* Create a new table
|
|
408
|
+
*/
|
|
409
|
+
createTable(name: string, schema: TableSchema): Promise<TableInfo>;
|
|
410
|
+
/**
|
|
411
|
+
* Get table information
|
|
412
|
+
*/
|
|
413
|
+
getTable(name: string): Promise<TableInfo | null>;
|
|
414
|
+
/**
|
|
415
|
+
* List all tables
|
|
416
|
+
*/
|
|
417
|
+
listTables(): Promise<TableInfo[]>;
|
|
418
|
+
/**
|
|
419
|
+
* Delete a table
|
|
420
|
+
*/
|
|
421
|
+
deleteTable(name: string): Promise<boolean>;
|
|
422
|
+
/**
|
|
423
|
+
* Insert a document into a collection
|
|
424
|
+
*/
|
|
425
|
+
insert<T extends BaseRecord>(collection: string, data: Partial<T>): Promise<T>;
|
|
426
|
+
/**
|
|
427
|
+
* Query documents from a collection
|
|
428
|
+
*/
|
|
429
|
+
query<T extends BaseRecord>(collection: string, options?: QueryOptions): Promise<T[]>;
|
|
430
|
+
/**
|
|
431
|
+
* Get a single document by ID
|
|
432
|
+
*/
|
|
433
|
+
get<T extends BaseRecord>(collection: string, id: string): Promise<T | null>;
|
|
434
|
+
/**
|
|
435
|
+
* Update a document
|
|
436
|
+
*/
|
|
437
|
+
update<T extends BaseRecord>(collection: string, id: string, data: Partial<T>): Promise<T>;
|
|
438
|
+
/**
|
|
439
|
+
* Delete a document
|
|
440
|
+
*/
|
|
441
|
+
delete(collection: string, id: string): Promise<boolean>;
|
|
442
|
+
/**
|
|
443
|
+
* Count documents in a collection
|
|
444
|
+
*/
|
|
445
|
+
count(collection: string, where?: Record<string, unknown>): Promise<number>;
|
|
446
|
+
/**
|
|
447
|
+
* Set a key-value pair
|
|
448
|
+
*/
|
|
449
|
+
setKV<T = unknown>(key: string, value: T): Promise<void>;
|
|
450
|
+
/**
|
|
451
|
+
* Get a value by key
|
|
452
|
+
*/
|
|
453
|
+
getKV<T = unknown>(key: string): Promise<T | null>;
|
|
454
|
+
/**
|
|
455
|
+
* Delete a key-value pair
|
|
456
|
+
*/
|
|
457
|
+
deleteKV(key: string): Promise<boolean>;
|
|
458
|
+
/**
|
|
459
|
+
* Subscribe to real-time changes on a collection
|
|
460
|
+
*/
|
|
461
|
+
subscribe<T extends BaseRecord>(collection: string, callback: (payload: RealtimePayload<T>) => void): Subscription;
|
|
462
|
+
/**
|
|
463
|
+
* Unsubscribe from all subscriptions
|
|
464
|
+
*/
|
|
465
|
+
unsubscribeAll(): void;
|
|
466
|
+
/**
|
|
467
|
+
* Get the project ID
|
|
468
|
+
*/
|
|
469
|
+
getProjectId(): string;
|
|
470
|
+
/**
|
|
471
|
+
* Get the base URL
|
|
472
|
+
*/
|
|
473
|
+
getBaseUrl(): string;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* VlibeBaseAuth - SSO Authentication for Vlibe Base Apps
|
|
478
|
+
*
|
|
479
|
+
* Provides single sign-on authentication for users logged into Vlibe.
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```typescript
|
|
483
|
+
* import { VlibeBaseAuth } from '@withvlibe/base-sdk';
|
|
484
|
+
*
|
|
485
|
+
* const auth = new VlibeBaseAuth({
|
|
486
|
+
* appId: process.env.VLIBE_BASE_APP_ID!,
|
|
487
|
+
* appSecret: process.env.VLIBE_BASE_APP_SECRET!,
|
|
488
|
+
* });
|
|
489
|
+
*
|
|
490
|
+
* // Verify a session token
|
|
491
|
+
* const user = await auth.verifySession(token);
|
|
492
|
+
*
|
|
493
|
+
* // Get login URL for unauthenticated users
|
|
494
|
+
* const loginUrl = auth.getLoginUrl('/dashboard');
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
|
|
498
|
+
declare class VlibeBaseAuth {
|
|
499
|
+
private appId;
|
|
500
|
+
private appSecret;
|
|
501
|
+
private baseUrl;
|
|
502
|
+
/**
|
|
503
|
+
* Create a new VlibeBaseAuth instance
|
|
504
|
+
*
|
|
505
|
+
* @param config - Authentication configuration
|
|
506
|
+
* @throws Error if appId or appSecret is missing
|
|
507
|
+
*/
|
|
508
|
+
constructor(config: AuthConfig);
|
|
509
|
+
/**
|
|
510
|
+
* Verify a session token and get user information
|
|
511
|
+
*
|
|
512
|
+
* @param token - The session token from the SSO callback
|
|
513
|
+
* @returns The user object if valid, null otherwise
|
|
514
|
+
*/
|
|
515
|
+
verifySession(token: string): Promise<VlibeUser | null>;
|
|
516
|
+
/**
|
|
517
|
+
* Generate the SSO login URL to redirect unauthenticated users
|
|
518
|
+
*
|
|
519
|
+
* @param redirectPath - The path to redirect to after login
|
|
520
|
+
* @returns The full Vlibe SSO URL
|
|
521
|
+
*/
|
|
522
|
+
getLoginUrl(redirectPath?: string): string;
|
|
523
|
+
/**
|
|
524
|
+
* Generate the logout URL
|
|
525
|
+
*
|
|
526
|
+
* @param redirectPath - The path to redirect to after logout
|
|
527
|
+
* @returns The logout URL
|
|
528
|
+
*/
|
|
529
|
+
getLogoutUrl(redirectPath?: string): string;
|
|
530
|
+
/**
|
|
531
|
+
* Check if user has access to a specific feature
|
|
532
|
+
*
|
|
533
|
+
* @param user - The Vlibe user object
|
|
534
|
+
* @param feature - The feature name to check
|
|
535
|
+
* @returns True if user has access to the feature
|
|
536
|
+
*/
|
|
537
|
+
hasFeature(user: VlibeUser | null, feature: string): boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Check if user has an active subscription
|
|
540
|
+
*
|
|
541
|
+
* @param user - The Vlibe user object
|
|
542
|
+
* @returns True if user has any active subscription
|
|
543
|
+
*/
|
|
544
|
+
hasSubscription(user: VlibeUser | null): boolean;
|
|
545
|
+
/**
|
|
546
|
+
* Get the subscription tier for a user
|
|
547
|
+
*
|
|
548
|
+
* @param user - The Vlibe user object
|
|
549
|
+
* @returns The tier name or null
|
|
550
|
+
*/
|
|
551
|
+
getTier(user: VlibeUser | null): string | null;
|
|
552
|
+
/**
|
|
553
|
+
* Get the app ID
|
|
554
|
+
*/
|
|
555
|
+
getAppId(): string;
|
|
556
|
+
/**
|
|
557
|
+
* Get the base URL
|
|
558
|
+
*/
|
|
559
|
+
getBaseUrl(): string;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
export { type AppCategory as A, type BasePlan as B, type ConnectStatus as C, type DatabaseConfig as D, type FeatureFlag as F, type Media as M, type Order as O, type PaymentsConfig as P, type QueryOptions as Q, type RefundOptions as R, type Subscription as S, type Transaction as T, type UsageMetric as U, VlibeBaseDatabase as V, type CheckoutOptions as a, type CheckoutSession as b, VlibeBaseAuth as c, type VlibeBaseConfig as d, type AuthConfig as e, type ColumnType as f, type TableColumn as g, type TableSchema as h, type TableInfo as i, type BaseRecord as j, type RealtimePayload as k, type VlibeUser as l, type VerifyResponse as m, type AuthSession as n, type Page as o, type Product as p, type OrderItem as q, type Address as r, type CartItem as s, type ApiResponse as t, type PaginatedResponse as u, type UseCollectionReturn as v, type UseCollectionOptions as w, type UseKVReturn as x, type UseAuthReturn as y, type UsePaymentsReturn as z };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { P as PaymentsConfig, C as ConnectStatus, a as CheckoutOptions, b as CheckoutSession, T as Transaction, R as RefundOptions } from './VlibeBaseAuth-ChuzgzDl.mjs';
|
|
2
|
+
export { r as Address, t as ApiResponse, A as AppCategory, e as AuthConfig, n as AuthSession, B as BasePlan, j as BaseRecord, s as CartItem, f as ColumnType, D as DatabaseConfig, F as FeatureFlag, M as Media, O as Order, q as OrderItem, o as Page, u as PaginatedResponse, p as Product, Q as QueryOptions, k as RealtimePayload, S as Subscription, g as TableColumn, i as TableInfo, h as TableSchema, U as UsageMetric, y as UseAuthReturn, w as UseCollectionOptions, v as UseCollectionReturn, x as UseKVReturn, z as UsePaymentsReturn, m as VerifyResponse, c as VlibeBaseAuth, d as VlibeBaseConfig, V as VlibeBaseDatabase, l as VlibeUser } from './VlibeBaseAuth-ChuzgzDl.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* VlibeBasePayments - Payment processing for Vlibe Base Apps
|
|
6
|
+
*
|
|
7
|
+
* Provides Stripe Connect payment processing with transaction fees.
|
|
8
|
+
* Unlike Vlibe Official (50/50 revenue split), Base apps pay a small
|
|
9
|
+
* transaction fee (0.5-2% depending on plan).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { VlibeBasePayments } from '@withvlibe/base-sdk';
|
|
14
|
+
*
|
|
15
|
+
* const payments = new VlibeBasePayments({
|
|
16
|
+
* appId: process.env.VLIBE_BASE_APP_ID!,
|
|
17
|
+
* appSecret: process.env.VLIBE_BASE_APP_SECRET!,
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Create a checkout session
|
|
21
|
+
* const session = await payments.createCheckout({
|
|
22
|
+
* amount: 1999, // $19.99 in cents
|
|
23
|
+
* successUrl: '/success',
|
|
24
|
+
* cancelUrl: '/cancel',
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Redirect user to session.url
|
|
28
|
+
*
|
|
29
|
+
* // Get transaction history
|
|
30
|
+
* const transactions = await payments.getTransactions();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
declare class VlibeBasePayments {
|
|
35
|
+
private appId;
|
|
36
|
+
private appSecret;
|
|
37
|
+
private baseUrl;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new VlibeBasePayments instance
|
|
40
|
+
*
|
|
41
|
+
* @param config - Payments configuration
|
|
42
|
+
* @throws Error if appId or appSecret is missing
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* This class should only be used server-side. Never expose your
|
|
46
|
+
* appSecret to the client.
|
|
47
|
+
*/
|
|
48
|
+
constructor(config: PaymentsConfig);
|
|
49
|
+
/**
|
|
50
|
+
* Make an authenticated API request
|
|
51
|
+
*/
|
|
52
|
+
private apiRequest;
|
|
53
|
+
/**
|
|
54
|
+
* Get Stripe Connect onboarding URL
|
|
55
|
+
*
|
|
56
|
+
* Redirect users to this URL to connect their Stripe account.
|
|
57
|
+
*
|
|
58
|
+
* @param returnUrl - URL to return to after onboarding
|
|
59
|
+
* @returns The Stripe Connect onboarding URL
|
|
60
|
+
*/
|
|
61
|
+
getConnectOnboardingUrl(returnUrl: string): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Check Stripe Connect status
|
|
64
|
+
*
|
|
65
|
+
* @returns The current Stripe Connect status
|
|
66
|
+
*/
|
|
67
|
+
getConnectStatus(): Promise<ConnectStatus>;
|
|
68
|
+
/**
|
|
69
|
+
* Create a checkout session for one-time payments
|
|
70
|
+
*
|
|
71
|
+
* @param options - Checkout options
|
|
72
|
+
* @returns The checkout session with URL to redirect user
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* Transaction fees are automatically calculated based on your plan:
|
|
76
|
+
* - Free plan: 2% of transaction
|
|
77
|
+
* - Premium plan: 0.5% of transaction
|
|
78
|
+
*/
|
|
79
|
+
createCheckout(options: CheckoutOptions): Promise<CheckoutSession>;
|
|
80
|
+
/**
|
|
81
|
+
* Get checkout session by ID
|
|
82
|
+
*
|
|
83
|
+
* @param sessionId - The checkout session ID
|
|
84
|
+
* @returns The checkout session details
|
|
85
|
+
*/
|
|
86
|
+
getCheckoutSession(sessionId: string): Promise<CheckoutSession | null>;
|
|
87
|
+
/**
|
|
88
|
+
* Get all transactions
|
|
89
|
+
*
|
|
90
|
+
* @param options - Query options
|
|
91
|
+
* @returns List of transactions
|
|
92
|
+
*/
|
|
93
|
+
getTransactions(options?: {
|
|
94
|
+
limit?: number;
|
|
95
|
+
offset?: number;
|
|
96
|
+
status?: 'pending' | 'succeeded' | 'failed' | 'refunded';
|
|
97
|
+
}): Promise<Transaction[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Get a single transaction
|
|
100
|
+
*
|
|
101
|
+
* @param transactionId - The transaction ID
|
|
102
|
+
* @returns The transaction details
|
|
103
|
+
*/
|
|
104
|
+
getTransaction(transactionId: string): Promise<Transaction | null>;
|
|
105
|
+
/**
|
|
106
|
+
* Get transaction summary/stats
|
|
107
|
+
*
|
|
108
|
+
* @returns Transaction statistics
|
|
109
|
+
*/
|
|
110
|
+
getTransactionStats(): Promise<{
|
|
111
|
+
totalRevenue: number;
|
|
112
|
+
totalFees: number;
|
|
113
|
+
netRevenue: number;
|
|
114
|
+
transactionCount: number;
|
|
115
|
+
thisMonth: {
|
|
116
|
+
revenue: number;
|
|
117
|
+
fees: number;
|
|
118
|
+
net: number;
|
|
119
|
+
count: number;
|
|
120
|
+
};
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Create a refund
|
|
124
|
+
*
|
|
125
|
+
* @param options - Refund options
|
|
126
|
+
* @returns The updated transaction
|
|
127
|
+
*
|
|
128
|
+
* @remarks
|
|
129
|
+
* Note: Transaction fees are not refunded when you issue a refund.
|
|
130
|
+
*/
|
|
131
|
+
createRefund(options: RefundOptions): Promise<Transaction>;
|
|
132
|
+
/**
|
|
133
|
+
* Calculate the Vlibe fee for an amount
|
|
134
|
+
*
|
|
135
|
+
* @param amount - Amount in cents
|
|
136
|
+
* @param plan - The Base plan ('free' or 'premium')
|
|
137
|
+
* @returns The fee amount in cents
|
|
138
|
+
*/
|
|
139
|
+
calculateFee(amount: number, plan?: 'free' | 'premium'): number;
|
|
140
|
+
/**
|
|
141
|
+
* Calculate net amount after fees
|
|
142
|
+
*
|
|
143
|
+
* @param amount - Gross amount in cents
|
|
144
|
+
* @param plan - The Base plan ('free' or 'premium')
|
|
145
|
+
* @returns The net amount in cents
|
|
146
|
+
*/
|
|
147
|
+
calculateNetAmount(amount: number, plan?: 'free' | 'premium'): number;
|
|
148
|
+
/**
|
|
149
|
+
* Get the app ID
|
|
150
|
+
*/
|
|
151
|
+
getAppId(): string;
|
|
152
|
+
/**
|
|
153
|
+
* Get the base URL
|
|
154
|
+
*/
|
|
155
|
+
getBaseUrl(): string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { CheckoutOptions, CheckoutSession, ConnectStatus, PaymentsConfig, RefundOptions, Transaction, VlibeBasePayments };
|