@pubflow/core 0.3.1 → 0.4.1

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
@@ -2,6 +2,12 @@
2
2
 
3
3
  Core functionality for the Pubflow framework.
4
4
 
5
+ ## 📚 Documentation
6
+
7
+ - **Flowless (Authentication Backend)**: [https://flowless.dev/](https://flowless.dev/)
8
+ - **Flowfull Client Libraries**: [https://clients.flowfull.dev/](https://clients.flowfull.dev/)
9
+ - **Bridge Payments**: [https://bridgepayments.dev/](https://bridgepayments.dev/)
10
+
5
11
  ## Overview
6
12
 
7
13
  `@pubflow/core` provides the foundation for the Pubflow framework, including:
@@ -10,6 +16,7 @@ Core functionality for the Pubflow framework.
10
16
  - API client for making authenticated HTTP requests
11
17
  - Authentication service for user management and session handling
12
18
  - Bridge API service for standardized CRUD operations
19
+ - **Bridge Payment Client** for payment processing (NEW in v0.4.0)
13
20
  - Schema validation using Zod
14
21
  - Storage adapter interface for different storage mechanisms
15
22
  - Utility functions for common tasks
@@ -161,4 +168,41 @@ const result = validateWithSchema(schemas.create, {
161
168
  if (!result.success) {
162
169
  console.error(result.errors);
163
170
  }
164
- ```
171
+ ```
172
+
173
+ ### Bridge Payments (NEW in v0.4.0)
174
+
175
+ ```typescript
176
+ import { BridgePaymentClient } from '@pubflow/core';
177
+
178
+ // Create payment client
179
+ const paymentClient = new BridgePaymentClient({
180
+ baseUrl: 'https://payments.example.com',
181
+ storage: new LocalStorageAdapter() // Optional, defaults to MemoryStorage
182
+ });
183
+
184
+ // Create payment intent
185
+ const intent = await paymentClient.createPaymentIntent({
186
+ total_cents: 2000, // $20.00
187
+ currency: 'USD',
188
+ description: 'Premium Subscription',
189
+ provider_id: 'stripe'
190
+ });
191
+
192
+ // List payment methods
193
+ const methods = await paymentClient.listPaymentMethods();
194
+
195
+ // Create subscription
196
+ const subscription = await paymentClient.createSubscription({
197
+ plan_id: 'plan_premium_monthly',
198
+ payment_method_id: 'pm_123'
199
+ });
200
+
201
+ // Manage organizations (multi-tenant)
202
+ const org = await paymentClient.createOrganization({
203
+ name: 'Acme Corp',
204
+ email: 'billing@acme.com'
205
+ });
206
+ ```
207
+
208
+ For complete payment integration examples, see the [Bridge Payments documentation](https://bridgepayments.dev/).
package/dist/index.d.ts CHANGED
@@ -17,3 +17,5 @@ export type { LoginCredentials, LoginResult, SessionValidationResult, SessionRef
17
17
  export { ApiClient } from './api/client';
18
18
  export { AuthService } from './auth/service';
19
19
  export { StorageAdapter } from './storage/adapter';
20
+ export * from './payments';
21
+ export { BridgePaymentClient } from './payments/client';
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.AuthService = exports.ApiClient = void 0;
22
+ exports.BridgePaymentClient = exports.AuthService = exports.ApiClient = void 0;
23
23
  // Export API
24
24
  __exportStar(require("./api/client"), exports);
25
25
  __exportStar(require("./api/types"), exports);
@@ -40,3 +40,7 @@ Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function ()
40
40
  // Export auth service
41
41
  var service_1 = require("./auth/service");
42
42
  Object.defineProperty(exports, "AuthService", { enumerable: true, get: function () { return service_1.AuthService; } });
43
+ // Export Bridge Payments
44
+ __exportStar(require("./payments"), exports);
45
+ var client_2 = require("./payments/client");
46
+ Object.defineProperty(exports, "BridgePaymentClient", { enumerable: true, get: function () { return client_2.BridgePaymentClient; } });
@@ -0,0 +1,523 @@
1
+ /**
2
+ * Bridge Payment Client
3
+ *
4
+ * Client for interacting with Bridge Payments API
5
+ */
6
+ import { BridgePaymentConfig, PaymentRequestOptions, CreatePaymentIntentRequest, PaymentIntent, Payment, PaymentMethod, UpdatePaymentMethodRequest, Address, CreateAddressRequest, UpdateAddressRequest, Customer, CreateCustomerRequest, UpdateCustomerRequest, Subscription, CreateSubscriptionRequest, CancelSubscriptionRequest, Organization, CreateOrganizationRequest, UpdateOrganizationRequest, OrganizationMember, AddOrganizationMemberRequest, UpdateOrganizationMemberRoleRequest, ConvertGuestToUserRequest, ConvertGuestToUserResponse, PaginationParams, BillingSchedule, CreateBillingScheduleRequest, UpdateBillingScheduleRequest, BillingExecution, AccountBalance, CreateAccountBalanceRequest, UpdateAccountBalanceRequest, CreditBalanceRequest, DebitBalanceRequest, AccountTransaction, ProductCost, CreateProductCostRequest, UpdateProductCostRequest, OrderCost, CreateOrderCostRequest, TotalCostResponse } from './types';
7
+ /**
8
+ * Bridge Payment Client
9
+ *
10
+ * Provides a simple interface for interacting with Bridge Payments API
11
+ */
12
+ export declare class BridgePaymentClient {
13
+ private apiClient;
14
+ private guestToken?;
15
+ private organizationId?;
16
+ private baseUrl;
17
+ /**
18
+ * Create a new Bridge Payment Client
19
+ *
20
+ * @param config Client configuration
21
+ */
22
+ constructor(config: BridgePaymentConfig);
23
+ /**
24
+ * Make a request to the Bridge Payments API
25
+ *
26
+ * @param endpoint API endpoint
27
+ * @param method HTTP method
28
+ * @param body Request body
29
+ * @param options Request options
30
+ * @returns Response data
31
+ */
32
+ private request;
33
+ /**
34
+ * Create a payment intent
35
+ *
36
+ * @param data Payment intent data
37
+ * @param options Request options
38
+ * @returns Payment intent
39
+ */
40
+ createPaymentIntent(data: CreatePaymentIntentRequest, options?: PaymentRequestOptions): Promise<PaymentIntent>;
41
+ /**
42
+ * Get a payment intent by ID
43
+ *
44
+ * @param id Payment intent ID
45
+ * @param options Request options
46
+ * @returns Payment intent
47
+ */
48
+ getPaymentIntent(id: string, options?: PaymentRequestOptions): Promise<PaymentIntent>;
49
+ /**
50
+ * List payments
51
+ *
52
+ * @param params Pagination parameters
53
+ * @param options Request options
54
+ * @returns List of payments
55
+ */
56
+ listPayments(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Payment[]>;
57
+ /**
58
+ * Get a payment by ID
59
+ *
60
+ * @param id Payment ID
61
+ * @param options Request options
62
+ * @returns Payment
63
+ */
64
+ getPayment(id: string, options?: PaymentRequestOptions): Promise<Payment>;
65
+ /**
66
+ * List payment methods
67
+ *
68
+ * @param params Pagination parameters
69
+ * @param options Request options
70
+ * @returns List of payment methods
71
+ */
72
+ listPaymentMethods(params?: PaginationParams, options?: PaymentRequestOptions): Promise<PaymentMethod[]>;
73
+ /**
74
+ * Get a payment method by ID
75
+ *
76
+ * @param id Payment method ID
77
+ * @param options Request options
78
+ * @returns Payment method
79
+ */
80
+ getPaymentMethod(id: string, options?: PaymentRequestOptions): Promise<PaymentMethod>;
81
+ /**
82
+ * Update a payment method
83
+ *
84
+ * @param id Payment method ID
85
+ * @param data Update data
86
+ * @param options Request options
87
+ * @returns Updated payment method
88
+ */
89
+ updatePaymentMethod(id: string, data: UpdatePaymentMethodRequest, options?: PaymentRequestOptions): Promise<PaymentMethod>;
90
+ /**
91
+ * Delete a payment method
92
+ *
93
+ * @param id Payment method ID
94
+ * @param options Request options
95
+ */
96
+ deletePaymentMethod(id: string, options?: PaymentRequestOptions): Promise<void>;
97
+ /**
98
+ * Create an address
99
+ *
100
+ * @param data Address data
101
+ * @param options Request options
102
+ * @returns Created address
103
+ */
104
+ createAddress(data: CreateAddressRequest, options?: PaymentRequestOptions): Promise<Address>;
105
+ /**
106
+ * List addresses
107
+ *
108
+ * @param params Pagination parameters
109
+ * @param options Request options
110
+ * @returns List of addresses
111
+ */
112
+ listAddresses(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Address[]>;
113
+ /**
114
+ * Get an address by ID
115
+ *
116
+ * @param id Address ID
117
+ * @param options Request options
118
+ * @returns Address
119
+ */
120
+ getAddress(id: string, options?: PaymentRequestOptions): Promise<Address>;
121
+ /**
122
+ * Update an address
123
+ *
124
+ * @param id Address ID
125
+ * @param data Update data
126
+ * @param options Request options
127
+ * @returns Updated address
128
+ */
129
+ updateAddress(id: string, data: UpdateAddressRequest, options?: PaymentRequestOptions): Promise<Address>;
130
+ /**
131
+ * Delete an address
132
+ *
133
+ * @param id Address ID
134
+ * @param options Request options
135
+ */
136
+ deleteAddress(id: string, options?: PaymentRequestOptions): Promise<void>;
137
+ /**
138
+ * Create a customer
139
+ *
140
+ * @param data Customer data
141
+ * @param options Request options
142
+ * @returns Created customer
143
+ */
144
+ createCustomer(data: CreateCustomerRequest, options?: PaymentRequestOptions): Promise<Customer>;
145
+ /**
146
+ * List customers
147
+ *
148
+ * @param params Pagination parameters
149
+ * @param options Request options
150
+ * @returns List of customers
151
+ */
152
+ listCustomers(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Customer[]>;
153
+ /**
154
+ * Get a customer by ID
155
+ *
156
+ * @param id Customer ID
157
+ * @param options Request options
158
+ * @returns Customer
159
+ */
160
+ getCustomer(id: string, options?: PaymentRequestOptions): Promise<Customer>;
161
+ /**
162
+ * Update a customer
163
+ *
164
+ * @param id Customer ID
165
+ * @param data Update data
166
+ * @param options Request options
167
+ * @returns Updated customer
168
+ */
169
+ updateCustomer(id: string, data: UpdateCustomerRequest, options?: PaymentRequestOptions): Promise<Customer>;
170
+ /**
171
+ * Delete a customer
172
+ *
173
+ * @param id Customer ID
174
+ * @param options Request options
175
+ */
176
+ deleteCustomer(id: string, options?: PaymentRequestOptions): Promise<void>;
177
+ /**
178
+ * Create a subscription
179
+ *
180
+ * @param data Subscription data
181
+ * @param options Request options
182
+ * @returns Created subscription
183
+ */
184
+ createSubscription(data: CreateSubscriptionRequest, options?: PaymentRequestOptions): Promise<Subscription>;
185
+ /**
186
+ * List subscriptions
187
+ *
188
+ * @param params Pagination parameters
189
+ * @param options Request options
190
+ * @returns List of subscriptions
191
+ */
192
+ listSubscriptions(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Subscription[]>;
193
+ /**
194
+ * Get a subscription by ID
195
+ *
196
+ * @param id Subscription ID
197
+ * @param options Request options
198
+ * @returns Subscription
199
+ */
200
+ getSubscription(id: string, options?: PaymentRequestOptions): Promise<Subscription>;
201
+ /**
202
+ * Cancel a subscription
203
+ *
204
+ * @param id Subscription ID
205
+ * @param data Cancel data
206
+ * @param options Request options
207
+ * @returns Canceled subscription
208
+ */
209
+ cancelSubscription(id: string, data?: CancelSubscriptionRequest, options?: PaymentRequestOptions): Promise<Subscription>;
210
+ /**
211
+ * Create an organization
212
+ *
213
+ * @param data Organization data
214
+ * @param options Request options
215
+ * @returns Created organization
216
+ */
217
+ createOrganization(data: CreateOrganizationRequest, options?: PaymentRequestOptions): Promise<Organization>;
218
+ /**
219
+ * List organizations
220
+ *
221
+ * @param params Pagination parameters
222
+ * @param options Request options
223
+ * @returns List of organizations
224
+ */
225
+ listOrganizations(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Organization[]>;
226
+ /**
227
+ * Get an organization by ID
228
+ *
229
+ * @param id Organization ID
230
+ * @param options Request options
231
+ * @returns Organization
232
+ */
233
+ getOrganization(id: string, options?: PaymentRequestOptions): Promise<Organization>;
234
+ /**
235
+ * Update an organization
236
+ *
237
+ * @param id Organization ID
238
+ * @param data Update data
239
+ * @param options Request options
240
+ * @returns Updated organization
241
+ */
242
+ updateOrganization(id: string, data: UpdateOrganizationRequest, options?: PaymentRequestOptions): Promise<Organization>;
243
+ /**
244
+ * Delete an organization
245
+ *
246
+ * @param id Organization ID
247
+ * @param options Request options
248
+ */
249
+ deleteOrganization(id: string, options?: PaymentRequestOptions): Promise<void>;
250
+ /**
251
+ * List organization members
252
+ *
253
+ * @param organizationId Organization ID
254
+ * @param params Pagination parameters
255
+ * @param options Request options
256
+ * @returns List of organization members
257
+ */
258
+ listOrganizationMembers(organizationId: string, params?: PaginationParams, options?: PaymentRequestOptions): Promise<OrganizationMember[]>;
259
+ /**
260
+ * Add an organization member
261
+ *
262
+ * @param organizationId Organization ID
263
+ * @param data Member data
264
+ * @param options Request options
265
+ * @returns Added member
266
+ */
267
+ addOrganizationMember(organizationId: string, data: AddOrganizationMemberRequest, options?: PaymentRequestOptions): Promise<OrganizationMember>;
268
+ /**
269
+ * Update an organization member role
270
+ *
271
+ * @param organizationId Organization ID
272
+ * @param memberId Member ID
273
+ * @param data Update data
274
+ * @param options Request options
275
+ * @returns Updated member
276
+ */
277
+ updateOrganizationMemberRole(organizationId: string, memberId: string, data: UpdateOrganizationMemberRoleRequest, options?: PaymentRequestOptions): Promise<OrganizationMember>;
278
+ /**
279
+ * Remove an organization member
280
+ *
281
+ * @param organizationId Organization ID
282
+ * @param memberId Member ID
283
+ * @param options Request options
284
+ */
285
+ removeOrganizationMember(organizationId: string, memberId: string, options?: PaymentRequestOptions): Promise<void>;
286
+ /**
287
+ * Leave an organization
288
+ *
289
+ * @param organizationId Organization ID
290
+ * @param options Request options
291
+ */
292
+ leaveOrganization(organizationId: string, options?: PaymentRequestOptions): Promise<void>;
293
+ /**
294
+ * Convert guest to user
295
+ *
296
+ * @param data Conversion data
297
+ * @param options Request options
298
+ * @returns Conversion result
299
+ */
300
+ convertGuestToUser(data: ConvertGuestToUserRequest, options?: PaymentRequestOptions): Promise<ConvertGuestToUserResponse>;
301
+ /**
302
+ * List my billing schedules
303
+ *
304
+ * @param params Pagination parameters
305
+ * @param options Request options
306
+ * @returns List of billing schedules
307
+ */
308
+ listMySchedules(params?: PaginationParams, options?: PaymentRequestOptions): Promise<BillingSchedule[]>;
309
+ /**
310
+ * Get a billing schedule by ID
311
+ *
312
+ * @param id Schedule ID
313
+ * @param options Request options
314
+ * @returns Billing schedule
315
+ */
316
+ getSchedule(id: string, options?: PaymentRequestOptions): Promise<BillingSchedule>;
317
+ /**
318
+ * Create a billing schedule
319
+ *
320
+ * @param data Schedule data
321
+ * @param options Request options
322
+ * @returns Created billing schedule
323
+ */
324
+ createSchedule(data: CreateBillingScheduleRequest, options?: PaymentRequestOptions): Promise<BillingSchedule>;
325
+ /**
326
+ * Update a billing schedule
327
+ *
328
+ * @param id Schedule ID
329
+ * @param data Update data
330
+ * @param options Request options
331
+ * @returns Updated billing schedule
332
+ */
333
+ updateSchedule(id: string, data: UpdateBillingScheduleRequest, options?: PaymentRequestOptions): Promise<BillingSchedule>;
334
+ /**
335
+ * Pause a billing schedule
336
+ *
337
+ * @param id Schedule ID
338
+ * @param options Request options
339
+ * @returns Updated billing schedule
340
+ */
341
+ pauseSchedule(id: string, options?: PaymentRequestOptions): Promise<BillingSchedule>;
342
+ /**
343
+ * Resume a billing schedule
344
+ *
345
+ * @param id Schedule ID
346
+ * @param options Request options
347
+ * @returns Updated billing schedule
348
+ */
349
+ resumeSchedule(id: string, options?: PaymentRequestOptions): Promise<BillingSchedule>;
350
+ /**
351
+ * Delete a billing schedule
352
+ *
353
+ * @param id Schedule ID
354
+ * @param options Request options
355
+ */
356
+ deleteSchedule(id: string, options?: PaymentRequestOptions): Promise<void>;
357
+ /**
358
+ * Get execution history for a billing schedule
359
+ *
360
+ * @param id Schedule ID
361
+ * @param params Pagination parameters
362
+ * @param options Request options
363
+ * @returns List of billing executions
364
+ */
365
+ getScheduleExecutions(id: string, params?: PaginationParams, options?: PaymentRequestOptions): Promise<BillingExecution[]>;
366
+ /**
367
+ * List my account balances
368
+ *
369
+ * @param params Pagination parameters
370
+ * @param options Request options
371
+ * @returns List of account balances
372
+ */
373
+ listMyBalances(params?: PaginationParams, options?: PaymentRequestOptions): Promise<AccountBalance[]>;
374
+ /**
375
+ * Get an account balance by ID
376
+ *
377
+ * @param id Balance ID
378
+ * @param options Request options
379
+ * @returns Account balance
380
+ */
381
+ getBalance(id: string, options?: PaymentRequestOptions): Promise<AccountBalance>;
382
+ /**
383
+ * Create an account balance
384
+ *
385
+ * @param data Balance data
386
+ * @param options Request options
387
+ * @returns Created account balance
388
+ */
389
+ createBalance(data: CreateAccountBalanceRequest, options?: PaymentRequestOptions): Promise<AccountBalance>;
390
+ /**
391
+ * Credit an account balance
392
+ *
393
+ * @param id Balance ID
394
+ * @param data Credit data
395
+ * @param options Request options
396
+ * @returns Updated balance and transaction
397
+ */
398
+ creditBalance(id: string, data: CreditBalanceRequest, options?: PaymentRequestOptions): Promise<{
399
+ balance: AccountBalance;
400
+ transaction: AccountTransaction;
401
+ }>;
402
+ /**
403
+ * Debit an account balance
404
+ *
405
+ * @param id Balance ID
406
+ * @param data Debit data
407
+ * @param options Request options
408
+ * @returns Updated balance and transaction
409
+ */
410
+ debitBalance(id: string, data: DebitBalanceRequest, options?: PaymentRequestOptions): Promise<{
411
+ balance: AccountBalance;
412
+ transaction: AccountTransaction;
413
+ }>;
414
+ /**
415
+ * Update an account balance
416
+ *
417
+ * @param id Balance ID
418
+ * @param data Update data
419
+ * @param options Request options
420
+ * @returns Updated account balance
421
+ */
422
+ updateBalance(id: string, data: UpdateAccountBalanceRequest, options?: PaymentRequestOptions): Promise<AccountBalance>;
423
+ /**
424
+ * Delete an account balance
425
+ *
426
+ * @param id Balance ID
427
+ * @param options Request options
428
+ */
429
+ deleteBalance(id: string, options?: PaymentRequestOptions): Promise<void>;
430
+ /**
431
+ * List my account transactions
432
+ *
433
+ * @param params Pagination parameters
434
+ * @param options Request options
435
+ * @returns List of account transactions
436
+ */
437
+ listMyTransactions(params?: PaginationParams, options?: PaymentRequestOptions): Promise<AccountTransaction[]>;
438
+ /**
439
+ * Get transactions for a specific balance
440
+ *
441
+ * @param id Balance ID
442
+ * @param params Pagination parameters
443
+ * @param options Request options
444
+ * @returns List of account transactions
445
+ */
446
+ getBalanceTransactions(id: string, params?: PaginationParams, options?: PaymentRequestOptions): Promise<AccountTransaction[]>;
447
+ /**
448
+ * Get all costs for a product
449
+ *
450
+ * @param productId Product ID
451
+ * @param params Pagination parameters
452
+ * @param options Request options
453
+ * @returns List of product costs
454
+ */
455
+ getProductCosts(productId: string, params?: PaginationParams, options?: PaymentRequestOptions): Promise<ProductCost[]>;
456
+ /**
457
+ * Get active cost for a product
458
+ *
459
+ * @param productId Product ID
460
+ * @param date Date to check (ISO 8601)
461
+ * @param options Request options
462
+ * @returns Active product cost
463
+ */
464
+ getActiveProductCost(productId: string, date?: string, options?: PaymentRequestOptions): Promise<ProductCost>;
465
+ /**
466
+ * Get total cost for a product
467
+ *
468
+ * @param productId Product ID
469
+ * @param date Date to check (ISO 8601)
470
+ * @param options Request options
471
+ * @returns Total cost response
472
+ */
473
+ getTotalProductCost(productId: string, date?: string, options?: PaymentRequestOptions): Promise<TotalCostResponse>;
474
+ /**
475
+ * Create a product cost
476
+ *
477
+ * @param data Product cost data
478
+ * @param options Request options
479
+ * @returns Created product cost
480
+ */
481
+ createProductCost(data: CreateProductCostRequest, options?: PaymentRequestOptions): Promise<ProductCost>;
482
+ /**
483
+ * Update a product cost
484
+ *
485
+ * @param id Cost ID
486
+ * @param data Update data
487
+ * @param options Request options
488
+ * @returns Updated product cost
489
+ */
490
+ updateProductCost(id: string, data: UpdateProductCostRequest, options?: PaymentRequestOptions): Promise<ProductCost>;
491
+ /**
492
+ * Delete a product cost
493
+ *
494
+ * @param id Cost ID
495
+ * @param options Request options
496
+ */
497
+ deleteProductCost(id: string, options?: PaymentRequestOptions): Promise<void>;
498
+ /**
499
+ * Get all costs for an order
500
+ *
501
+ * @param orderId Order ID
502
+ * @param params Pagination parameters
503
+ * @param options Request options
504
+ * @returns List of order costs
505
+ */
506
+ getOrderCosts(orderId: string, params?: PaginationParams, options?: PaymentRequestOptions): Promise<OrderCost[]>;
507
+ /**
508
+ * Get total cost for an order
509
+ *
510
+ * @param orderId Order ID
511
+ * @param options Request options
512
+ * @returns Total cost response
513
+ */
514
+ getTotalOrderCost(orderId: string, options?: PaymentRequestOptions): Promise<TotalCostResponse>;
515
+ /**
516
+ * Create an order cost
517
+ *
518
+ * @param data Order cost data
519
+ * @param options Request options
520
+ * @returns Created order cost
521
+ */
522
+ createOrderCost(data: CreateOrderCostRequest, options?: PaymentRequestOptions): Promise<OrderCost>;
523
+ }