@pubflow/core 0.4.0 → 0.4.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.
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Two-Factor Authentication Service
3
+ *
4
+ * Thin client over the multi-flowless /auth/two_factor/* endpoints.
5
+ * All network calls delegate to ApiClient so session cookies are
6
+ * forwarded automatically.
7
+ */
8
+ import { ApiClient } from '../api/client';
9
+ import { PubflowInstanceConfig } from '../types';
10
+ import type { TwoFactorMethod, TwoFactorSystemInfo, TwoFactorStartResult, TwoFactorVerifyResult, TwoFactorSetupResult, TwoFactorToggleResult } from './types';
11
+ export declare class TwoFactorService {
12
+ private apiClient;
13
+ private basePath;
14
+ constructor(apiClient: ApiClient, config: PubflowInstanceConfig);
15
+ /**
16
+ * GET /auth/two_factor/system
17
+ * Returns system-level 2FA availability (no auth needed).
18
+ */
19
+ getSystem(): Promise<TwoFactorSystemInfo>;
20
+ /**
21
+ * GET /auth/two_factor/methods
22
+ * Returns the authenticated user's configured 2FA methods.
23
+ */
24
+ getMethods(): Promise<TwoFactorMethod[]>;
25
+ /**
26
+ * POST /auth/two_factor/:method/setup
27
+ * Begin setup for a 2FA method (email or sms).
28
+ */
29
+ setup(method: string, identifier: string): Promise<TwoFactorSetupResult>;
30
+ /**
31
+ * POST /auth/two_factor/:method/start
32
+ * (Re-)send a verification code for an existing method.
33
+ * Accepts BOTH active and pending sessions (used during login flow).
34
+ */
35
+ start(methodId: string, method: string, action?: string): Promise<TwoFactorStartResult>;
36
+ /**
37
+ * POST /auth/two_factor/verify
38
+ * Verify a 2FA code. For action='login' the pending session becomes active.
39
+ */
40
+ verify(methodId: string, code: string, action?: string): Promise<TwoFactorVerifyResult>;
41
+ /**
42
+ * POST /auth/two_factor/toggle
43
+ * Enable or disable 2FA for the current user.
44
+ */
45
+ toggle(enabled: boolean, verificationCode?: string, verificationMethodId?: string): Promise<TwoFactorToggleResult>;
46
+ /**
47
+ * DELETE /auth/two_factor/:id
48
+ * Remove a 2FA method. Requires verification via another active method.
49
+ */
50
+ removeMethod(methodId: string, verificationCode: string, verificationMethodId: string): Promise<{
51
+ success: boolean;
52
+ message?: string;
53
+ error?: string;
54
+ }>;
55
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /**
3
+ * Two-Factor Authentication Service
4
+ *
5
+ * Thin client over the multi-flowless /auth/two_factor/* endpoints.
6
+ * All network calls delegate to ApiClient so session cookies are
7
+ * forwarded automatically.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TwoFactorService = void 0;
11
+ class TwoFactorService {
12
+ constructor(apiClient, config) {
13
+ this.apiClient = apiClient;
14
+ this.basePath = `${config.authBasePath || '/auth'}/two_factor`;
15
+ }
16
+ // ─── Public (no auth) ──────────────────────────────────────────────────────
17
+ /**
18
+ * GET /auth/two_factor/system
19
+ * Returns system-level 2FA availability (no auth needed).
20
+ */
21
+ async getSystem() {
22
+ const res = await this.apiClient.get(`${this.basePath}/system`, { includeSession: false });
23
+ if (res.success && res.data)
24
+ return res.data;
25
+ return { global_two_factor_enabled: false, available_methods: [] };
26
+ }
27
+ // ─── User methods ──────────────────────────────────────────────────────────
28
+ /**
29
+ * GET /auth/two_factor/methods
30
+ * Returns the authenticated user's configured 2FA methods.
31
+ */
32
+ async getMethods() {
33
+ var _a;
34
+ const res = await this.apiClient.get(`${this.basePath}/methods`);
35
+ if (res.success && res.data)
36
+ return (_a = res.data.methods) !== null && _a !== void 0 ? _a : [];
37
+ return [];
38
+ }
39
+ // ─── Setup ────────────────────────────────────────────────────────────────
40
+ /**
41
+ * POST /auth/two_factor/:method/setup
42
+ * Begin setup for a 2FA method (email or sms).
43
+ */
44
+ async setup(method, identifier) {
45
+ const res = await this.apiClient.post(`${this.basePath}/${method}/setup`, { identifier });
46
+ if (res.success && res.data)
47
+ return res.data;
48
+ return { success: false, error: res.error || 'Setup failed' };
49
+ }
50
+ // ─── Start / Re-send ───────────────────────────────────────────────────────
51
+ /**
52
+ * POST /auth/two_factor/:method/start
53
+ * (Re-)send a verification code for an existing method.
54
+ * Accepts BOTH active and pending sessions (used during login flow).
55
+ */
56
+ async start(methodId, method, action = 'login') {
57
+ const res = await this.apiClient.post(`${this.basePath}/${method}/start`, { method_id: methodId, action });
58
+ if (res.success && res.data)
59
+ return res.data;
60
+ return { success: false, error: res.error || 'Failed to send code' };
61
+ }
62
+ // ─── Verify ───────────────────────────────────────────────────────────────
63
+ /**
64
+ * POST /auth/two_factor/verify
65
+ * Verify a 2FA code. For action='login' the pending session becomes active.
66
+ */
67
+ async verify(methodId, code, action = 'login') {
68
+ const res = await this.apiClient.post(`${this.basePath}/verify`, { method_id: methodId, code, action });
69
+ if (res.success && res.data)
70
+ return res.data;
71
+ // The server may return 400 with body even on wrong code — surface it
72
+ return {
73
+ success: false,
74
+ verified: false,
75
+ error: res.error || 'Verification failed',
76
+ };
77
+ }
78
+ // ─── Toggle ───────────────────────────────────────────────────────────────
79
+ /**
80
+ * POST /auth/two_factor/toggle
81
+ * Enable or disable 2FA for the current user.
82
+ */
83
+ async toggle(enabled, verificationCode, verificationMethodId) {
84
+ const res = await this.apiClient.post(`${this.basePath}/toggle`, {
85
+ two_factor_enabled: enabled,
86
+ ...(verificationCode && { verification_code: verificationCode }),
87
+ ...(verificationMethodId && { verification_method_id: verificationMethodId }),
88
+ });
89
+ if (res.success && res.data)
90
+ return res.data;
91
+ return { success: false, error: res.error || 'Toggle failed' };
92
+ }
93
+ // ─── Remove ───────────────────────────────────────────────────────────────
94
+ /**
95
+ * DELETE /auth/two_factor/:id
96
+ * Remove a 2FA method. Requires verification via another active method.
97
+ */
98
+ async removeMethod(methodId, verificationCode, verificationMethodId) {
99
+ const res = await this.apiClient.request(`${this.basePath}/${methodId}`, 'DELETE', {
100
+ verification_code: verificationCode,
101
+ verification_method_id: verificationMethodId,
102
+ });
103
+ if (res.success && res.data)
104
+ return res.data;
105
+ return { success: false, error: res.error || 'Remove failed' };
106
+ }
107
+ }
108
+ exports.TwoFactorService = TwoFactorService;
@@ -30,7 +30,7 @@ export interface LoginResult {
30
30
  */
31
31
  success: boolean;
32
32
  /**
33
- * User data (only present if success is true)
33
+ * User data (only present if success is true and 2FA is not required)
34
34
  */
35
35
  user?: User;
36
36
  /**
@@ -41,6 +41,16 @@ export interface LoginResult {
41
41
  * Error message (only present if success is false)
42
42
  */
43
43
  error?: string;
44
+ /**
45
+ * Whether 2FA verification is required to complete login.
46
+ * When true, the session is in "pending" status and must be
47
+ * activated via POST /auth/two_factor/verify.
48
+ */
49
+ requires2fa?: boolean;
50
+ /**
51
+ * Available 2FA methods the user has configured (present when requires2fa is true)
52
+ */
53
+ availableMethods?: TwoFactorMethod[];
44
54
  }
45
55
  /**
46
56
  * Result of a session validation
@@ -248,3 +258,67 @@ export interface RefreshResponse {
248
258
  */
249
259
  error?: string;
250
260
  }
261
+ /**
262
+ * A 2FA method configured by the user
263
+ */
264
+ export interface TwoFactorMethod {
265
+ id: string;
266
+ method: 'email' | 'sms' | 'totp' | string;
267
+ status: 'pending_setup' | 'active' | string;
268
+ identifier?: string | null;
269
+ last_used_at?: string | null;
270
+ created_at?: string;
271
+ }
272
+ /**
273
+ * System-level 2FA information (public endpoint)
274
+ */
275
+ export interface TwoFactorSystemInfo {
276
+ global_two_factor_enabled: boolean;
277
+ available_methods: string[];
278
+ }
279
+ /**
280
+ * Result of starting a 2FA verification (sending a code)
281
+ */
282
+ export interface TwoFactorStartResult {
283
+ success: boolean;
284
+ method?: string;
285
+ verification_sent?: boolean;
286
+ expires_in?: number;
287
+ message?: string;
288
+ error?: string;
289
+ }
290
+ /**
291
+ * Result of verifying a 2FA code
292
+ */
293
+ export interface TwoFactorVerifyResult {
294
+ success: boolean;
295
+ verified?: boolean;
296
+ session_activated?: boolean;
297
+ expires_at?: string | null;
298
+ attempts_remaining?: number;
299
+ message?: string;
300
+ error?: string;
301
+ }
302
+ /**
303
+ * Result of setting up a new 2FA method
304
+ */
305
+ export interface TwoFactorSetupResult {
306
+ success: boolean;
307
+ method_id?: string;
308
+ method?: string;
309
+ status?: string;
310
+ verification_sent?: boolean;
311
+ expires_in?: number;
312
+ message?: string;
313
+ error?: string;
314
+ }
315
+ /**
316
+ * Result of toggling 2FA for the user
317
+ */
318
+ export interface TwoFactorToggleResult {
319
+ success: boolean;
320
+ two_factor_enabled?: boolean;
321
+ active_methods?: string[];
322
+ message?: string;
323
+ error?: string;
324
+ }
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  export * from './api/client';
7
7
  export * from './api/types';
8
8
  export * from './auth/service';
9
+ export { TwoFactorService } from './auth/two-factor';
9
10
  export * from './bridge/service';
10
11
  export * from './bridge/types';
11
12
  export * from './config';
@@ -13,7 +14,7 @@ export * from './schema/validator';
13
14
  export * from './storage/adapter';
14
15
  export type { User, SessionConfig, StorageConfig, PubflowInstanceConfig, PaginationMeta } from './types';
15
16
  export type { PubflowInstanceConfig as PubflowConfig } from './types';
16
- export type { LoginCredentials, LoginResult, SessionValidationResult, SessionRefreshResult, RegistrationData, RegistrationResult, PasswordResetRequestData, PasswordResetData, AuthResponse, SessionResponse, ValidationResponse, RefreshResponse } from './auth/types';
17
+ export type { LoginCredentials, LoginResult, SessionValidationResult, SessionRefreshResult, RegistrationData, RegistrationResult, PasswordResetRequestData, PasswordResetData, AuthResponse, SessionResponse, ValidationResponse, RefreshResponse, TwoFactorMethod, TwoFactorSystemInfo, TwoFactorStartResult, TwoFactorVerifyResult, TwoFactorSetupResult, TwoFactorToggleResult, } from './auth/types';
17
18
  export { ApiClient } from './api/client';
18
19
  export { AuthService } from './auth/service';
19
20
  export { StorageAdapter } from './storage/adapter';
package/dist/index.js CHANGED
@@ -19,12 +19,14 @@ 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.BridgePaymentClient = exports.AuthService = exports.ApiClient = void 0;
22
+ exports.BridgePaymentClient = exports.AuthService = exports.ApiClient = exports.TwoFactorService = void 0;
23
23
  // Export API
24
24
  __exportStar(require("./api/client"), exports);
25
25
  __exportStar(require("./api/types"), exports);
26
26
  // Export Auth
27
27
  __exportStar(require("./auth/service"), exports);
28
+ var two_factor_1 = require("./auth/two-factor");
29
+ Object.defineProperty(exports, "TwoFactorService", { enumerable: true, get: function () { return two_factor_1.TwoFactorService; } });
28
30
  // Export Bridge
29
31
  __exportStar(require("./bridge/service"), exports);
30
32
  __exportStar(require("./bridge/types"), exports);
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Client for interacting with Bridge Payments API
5
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 } from './types';
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
7
  /**
8
8
  * Bridge Payment Client
9
9
  *
@@ -298,4 +298,226 @@ export declare class BridgePaymentClient {
298
298
  * @returns Conversion result
299
299
  */
300
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>;
301
523
  }
@@ -473,5 +473,332 @@ class BridgePaymentClient {
473
473
  async convertGuestToUser(data, options) {
474
474
  return this.request('/guest/convert', 'POST', data, options);
475
475
  }
476
+ // ============================================================================
477
+ // BILLING SCHEDULES
478
+ // ============================================================================
479
+ /**
480
+ * List my billing schedules
481
+ *
482
+ * @param params Pagination parameters
483
+ * @param options Request options
484
+ * @returns List of billing schedules
485
+ */
486
+ async listMySchedules(params, options) {
487
+ const queryParams = new URLSearchParams();
488
+ if (params === null || params === void 0 ? void 0 : params.page)
489
+ queryParams.set('page', params.page.toString());
490
+ if (params === null || params === void 0 ? void 0 : params.limit)
491
+ queryParams.set('limit', params.limit.toString());
492
+ const endpoint = `/billing-schedules/me${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
493
+ return this.request(endpoint, 'GET', undefined, options);
494
+ }
495
+ /**
496
+ * Get a billing schedule by ID
497
+ *
498
+ * @param id Schedule ID
499
+ * @param options Request options
500
+ * @returns Billing schedule
501
+ */
502
+ async getSchedule(id, options) {
503
+ return this.request(`/billing-schedules/${id}`, 'GET', undefined, options);
504
+ }
505
+ /**
506
+ * Create a billing schedule
507
+ *
508
+ * @param data Schedule data
509
+ * @param options Request options
510
+ * @returns Created billing schedule
511
+ */
512
+ async createSchedule(data, options) {
513
+ return this.request('/billing-schedules', 'POST', data, options);
514
+ }
515
+ /**
516
+ * Update a billing schedule
517
+ *
518
+ * @param id Schedule ID
519
+ * @param data Update data
520
+ * @param options Request options
521
+ * @returns Updated billing schedule
522
+ */
523
+ async updateSchedule(id, data, options) {
524
+ return this.request(`/billing-schedules/${id}`, 'PUT', data, options);
525
+ }
526
+ /**
527
+ * Pause a billing schedule
528
+ *
529
+ * @param id Schedule ID
530
+ * @param options Request options
531
+ * @returns Updated billing schedule
532
+ */
533
+ async pauseSchedule(id, options) {
534
+ return this.request(`/billing-schedules/${id}/pause`, 'POST', undefined, options);
535
+ }
536
+ /**
537
+ * Resume a billing schedule
538
+ *
539
+ * @param id Schedule ID
540
+ * @param options Request options
541
+ * @returns Updated billing schedule
542
+ */
543
+ async resumeSchedule(id, options) {
544
+ return this.request(`/billing-schedules/${id}/resume`, 'POST', undefined, options);
545
+ }
546
+ /**
547
+ * Delete a billing schedule
548
+ *
549
+ * @param id Schedule ID
550
+ * @param options Request options
551
+ */
552
+ async deleteSchedule(id, options) {
553
+ await this.request(`/billing-schedules/${id}`, 'DELETE', undefined, options);
554
+ }
555
+ /**
556
+ * Get execution history for a billing schedule
557
+ *
558
+ * @param id Schedule ID
559
+ * @param params Pagination parameters
560
+ * @param options Request options
561
+ * @returns List of billing executions
562
+ */
563
+ async getScheduleExecutions(id, params, options) {
564
+ const queryParams = new URLSearchParams();
565
+ if (params === null || params === void 0 ? void 0 : params.page)
566
+ queryParams.set('page', params.page.toString());
567
+ if (params === null || params === void 0 ? void 0 : params.limit)
568
+ queryParams.set('limit', params.limit.toString());
569
+ const endpoint = `/billing-schedules/${id}/executions${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
570
+ return this.request(endpoint, 'GET', undefined, options);
571
+ }
572
+ // ============================================================================
573
+ // ACCOUNT BALANCE
574
+ // ============================================================================
575
+ /**
576
+ * List my account balances
577
+ *
578
+ * @param params Pagination parameters
579
+ * @param options Request options
580
+ * @returns List of account balances
581
+ */
582
+ async listMyBalances(params, options) {
583
+ const queryParams = new URLSearchParams();
584
+ if (params === null || params === void 0 ? void 0 : params.page)
585
+ queryParams.set('page', params.page.toString());
586
+ if (params === null || params === void 0 ? void 0 : params.limit)
587
+ queryParams.set('limit', params.limit.toString());
588
+ const endpoint = `/account-balance/me/balances${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
589
+ return this.request(endpoint, 'GET', undefined, options);
590
+ }
591
+ /**
592
+ * Get an account balance by ID
593
+ *
594
+ * @param id Balance ID
595
+ * @param options Request options
596
+ * @returns Account balance
597
+ */
598
+ async getBalance(id, options) {
599
+ return this.request(`/account-balance/${id}`, 'GET', undefined, options);
600
+ }
601
+ /**
602
+ * Create an account balance
603
+ *
604
+ * @param data Balance data
605
+ * @param options Request options
606
+ * @returns Created account balance
607
+ */
608
+ async createBalance(data, options) {
609
+ return this.request('/account-balance', 'POST', data, options);
610
+ }
611
+ /**
612
+ * Credit an account balance
613
+ *
614
+ * @param id Balance ID
615
+ * @param data Credit data
616
+ * @param options Request options
617
+ * @returns Updated balance and transaction
618
+ */
619
+ async creditBalance(id, data, options) {
620
+ return this.request(`/account-balance/${id}/credit`, 'POST', data, options);
621
+ }
622
+ /**
623
+ * Debit an account balance
624
+ *
625
+ * @param id Balance ID
626
+ * @param data Debit data
627
+ * @param options Request options
628
+ * @returns Updated balance and transaction
629
+ */
630
+ async debitBalance(id, data, options) {
631
+ return this.request(`/account-balance/${id}/debit`, 'POST', data, options);
632
+ }
633
+ /**
634
+ * Update an account balance
635
+ *
636
+ * @param id Balance ID
637
+ * @param data Update data
638
+ * @param options Request options
639
+ * @returns Updated account balance
640
+ */
641
+ async updateBalance(id, data, options) {
642
+ return this.request(`/account-balance/${id}`, 'PUT', data, options);
643
+ }
644
+ /**
645
+ * Delete an account balance
646
+ *
647
+ * @param id Balance ID
648
+ * @param options Request options
649
+ */
650
+ async deleteBalance(id, options) {
651
+ await this.request(`/account-balance/${id}`, 'DELETE', undefined, options);
652
+ }
653
+ /**
654
+ * List my account transactions
655
+ *
656
+ * @param params Pagination parameters
657
+ * @param options Request options
658
+ * @returns List of account transactions
659
+ */
660
+ async listMyTransactions(params, options) {
661
+ const queryParams = new URLSearchParams();
662
+ if (params === null || params === void 0 ? void 0 : params.page)
663
+ queryParams.set('page', params.page.toString());
664
+ if (params === null || params === void 0 ? void 0 : params.limit)
665
+ queryParams.set('limit', params.limit.toString());
666
+ const endpoint = `/account-balance/me/transactions${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
667
+ return this.request(endpoint, 'GET', undefined, options);
668
+ }
669
+ /**
670
+ * Get transactions for a specific balance
671
+ *
672
+ * @param id Balance ID
673
+ * @param params Pagination parameters
674
+ * @param options Request options
675
+ * @returns List of account transactions
676
+ */
677
+ async getBalanceTransactions(id, params, options) {
678
+ const queryParams = new URLSearchParams();
679
+ if (params === null || params === void 0 ? void 0 : params.page)
680
+ queryParams.set('page', params.page.toString());
681
+ if (params === null || params === void 0 ? void 0 : params.limit)
682
+ queryParams.set('limit', params.limit.toString());
683
+ const endpoint = `/account-balance/${id}/transactions${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
684
+ return this.request(endpoint, 'GET', undefined, options);
685
+ }
686
+ // ============================================================================
687
+ // COST TRACKING
688
+ // ============================================================================
689
+ /**
690
+ * Get all costs for a product
691
+ *
692
+ * @param productId Product ID
693
+ * @param params Pagination parameters
694
+ * @param options Request options
695
+ * @returns List of product costs
696
+ */
697
+ async getProductCosts(productId, params, options) {
698
+ const queryParams = new URLSearchParams();
699
+ if (params === null || params === void 0 ? void 0 : params.page)
700
+ queryParams.set('page', params.page.toString());
701
+ if (params === null || params === void 0 ? void 0 : params.limit)
702
+ queryParams.set('limit', params.limit.toString());
703
+ const endpoint = `/cost-tracking/products/${productId}/costs${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
704
+ return this.request(endpoint, 'GET', undefined, options);
705
+ }
706
+ /**
707
+ * Get active cost for a product
708
+ *
709
+ * @param productId Product ID
710
+ * @param date Date to check (ISO 8601)
711
+ * @param options Request options
712
+ * @returns Active product cost
713
+ */
714
+ async getActiveProductCost(productId, date, options) {
715
+ const queryParams = new URLSearchParams();
716
+ if (date)
717
+ queryParams.set('date', date);
718
+ const endpoint = `/cost-tracking/products/${productId}/costs/active${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
719
+ return this.request(endpoint, 'GET', undefined, options);
720
+ }
721
+ /**
722
+ * Get total cost for a product
723
+ *
724
+ * @param productId Product ID
725
+ * @param date Date to check (ISO 8601)
726
+ * @param options Request options
727
+ * @returns Total cost response
728
+ */
729
+ async getTotalProductCost(productId, date, options) {
730
+ const queryParams = new URLSearchParams();
731
+ if (date)
732
+ queryParams.set('date', date);
733
+ const endpoint = `/cost-tracking/products/${productId}/costs/total${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
734
+ return this.request(endpoint, 'GET', undefined, options);
735
+ }
736
+ /**
737
+ * Create a product cost
738
+ *
739
+ * @param data Product cost data
740
+ * @param options Request options
741
+ * @returns Created product cost
742
+ */
743
+ async createProductCost(data, options) {
744
+ return this.request('/cost-tracking/products/costs', 'POST', data, options);
745
+ }
746
+ /**
747
+ * Update a product cost
748
+ *
749
+ * @param id Cost ID
750
+ * @param data Update data
751
+ * @param options Request options
752
+ * @returns Updated product cost
753
+ */
754
+ async updateProductCost(id, data, options) {
755
+ return this.request(`/cost-tracking/products/costs/${id}`, 'PUT', data, options);
756
+ }
757
+ /**
758
+ * Delete a product cost
759
+ *
760
+ * @param id Cost ID
761
+ * @param options Request options
762
+ */
763
+ async deleteProductCost(id, options) {
764
+ await this.request(`/cost-tracking/products/costs/${id}`, 'DELETE', undefined, options);
765
+ }
766
+ /**
767
+ * Get all costs for an order
768
+ *
769
+ * @param orderId Order ID
770
+ * @param params Pagination parameters
771
+ * @param options Request options
772
+ * @returns List of order costs
773
+ */
774
+ async getOrderCosts(orderId, params, options) {
775
+ const queryParams = new URLSearchParams();
776
+ if (params === null || params === void 0 ? void 0 : params.page)
777
+ queryParams.set('page', params.page.toString());
778
+ if (params === null || params === void 0 ? void 0 : params.limit)
779
+ queryParams.set('limit', params.limit.toString());
780
+ const endpoint = `/cost-tracking/orders/${orderId}/costs${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
781
+ return this.request(endpoint, 'GET', undefined, options);
782
+ }
783
+ /**
784
+ * Get total cost for an order
785
+ *
786
+ * @param orderId Order ID
787
+ * @param options Request options
788
+ * @returns Total cost response
789
+ */
790
+ async getTotalOrderCost(orderId, options) {
791
+ return this.request(`/cost-tracking/orders/${orderId}/costs/total`, 'GET', undefined, options);
792
+ }
793
+ /**
794
+ * Create an order cost
795
+ *
796
+ * @param data Order cost data
797
+ * @param options Request options
798
+ * @returns Created order cost
799
+ */
800
+ async createOrderCost(data, options) {
801
+ return this.request('/cost-tracking/orders/costs', 'POST', data, options);
802
+ }
476
803
  }
477
804
  exports.BridgePaymentClient = BridgePaymentClient;
@@ -4,4 +4,4 @@
4
4
  * Exports for Bridge Payments client and types
5
5
  */
6
6
  export { BridgePaymentClient } from './client';
7
- export type { BridgePaymentConfig, PaymentRequestOptions, CreatePaymentIntentRequest, PaymentIntent, Payment, PaymentMethodType, PaymentMethod, UpdatePaymentMethodRequest, AddressType, Address, CreateAddressRequest, UpdateAddressRequest, Customer, CreateCustomerRequest, UpdateCustomerRequest, SubscriptionStatus, Subscription, CreateSubscriptionRequest, CancelSubscriptionRequest, OrganizationRole, Organization, CreateOrganizationRequest, UpdateOrganizationRequest, OrganizationMember, AddOrganizationMemberRequest, UpdateOrganizationMemberRoleRequest, ConvertGuestToUserRequest, ConvertGuestToUserResponse, PaginationParams, ListResponse } from './types';
7
+ export type { BridgePaymentConfig, PaymentRequestOptions, CreatePaymentIntentRequest, PaymentIntent, Payment, PaymentMethodType, PaymentMethod, UpdatePaymentMethodRequest, AddressType, Address, CreateAddressRequest, UpdateAddressRequest, Customer, CreateCustomerRequest, UpdateCustomerRequest, SubscriptionStatus, Subscription, CreateSubscriptionRequest, CancelSubscriptionRequest, OrganizationRole, Organization, CreateOrganizationRequest, UpdateOrganizationRequest, OrganizationMember, AddOrganizationMemberRequest, UpdateOrganizationMemberRoleRequest, ConvertGuestToUserRequest, ConvertGuestToUserResponse, PaginationParams, ListResponse, ScheduleType, IntervalType, BillingScheduleStatus, BillingSchedule, CreateBillingScheduleRequest, UpdateBillingScheduleRequest, BillingExecution, BalanceType, BalanceStatus, TransactionType, AccountBalance, CreateAccountBalanceRequest, UpdateAccountBalanceRequest, CreditBalanceRequest, DebitBalanceRequest, AccountTransaction, CostType, ProductCost, CreateProductCostRequest, UpdateProductCostRequest, OrderCost, CreateOrderCostRequest, TotalCostResponse } from './types';
@@ -153,7 +153,7 @@ export interface UpdatePaymentMethodRequest {
153
153
  /**
154
154
  * Address type
155
155
  */
156
- export type AddressType = 'billing' | 'shipping';
156
+ export type AddressType = 'billing' | 'shipping' | 'both';
157
157
  /**
158
158
  * Address response
159
159
  */
@@ -171,6 +171,7 @@ export interface Address {
171
171
  postal_code: string;
172
172
  country: string;
173
173
  phone?: string;
174
+ email?: string;
174
175
  is_default: boolean;
175
176
  created_at: string;
176
177
  updated_at: string;
@@ -188,6 +189,7 @@ export interface CreateAddressRequest {
188
189
  postal_code: string;
189
190
  country: string;
190
191
  phone?: string;
192
+ email?: string;
191
193
  is_default?: boolean;
192
194
  }
193
195
  /**
@@ -382,3 +384,268 @@ export interface ListResponse<T> {
382
384
  hasMore: boolean;
383
385
  };
384
386
  }
387
+ /**
388
+ * Schedule type
389
+ */
390
+ export type ScheduleType = 'subscription' | 'installment' | 'recurring_invoice' | 'custom';
391
+ /**
392
+ * Interval type
393
+ */
394
+ export type IntervalType = 'daily' | 'weekly' | 'monthly' | 'yearly' | 'custom';
395
+ /**
396
+ * Billing schedule status
397
+ */
398
+ export type BillingScheduleStatus = 'active' | 'paused' | 'completed' | 'failed' | 'canceled';
399
+ /**
400
+ * Billing schedule response
401
+ */
402
+ export interface BillingSchedule {
403
+ id: string;
404
+ user_id?: string;
405
+ organization_id?: string;
406
+ schedule_type: ScheduleType;
407
+ amount_cents: number;
408
+ currency: string;
409
+ interval_type: IntervalType;
410
+ interval_count: number;
411
+ next_billing_date: string;
412
+ end_date?: string;
413
+ max_occurrences?: number;
414
+ current_occurrence: number;
415
+ payment_method_id?: string;
416
+ account_balance_id?: string;
417
+ auto_charge: boolean;
418
+ send_invoice: boolean;
419
+ retry_on_failure: boolean;
420
+ max_retries: number;
421
+ status: BillingScheduleStatus;
422
+ last_billing_date?: string;
423
+ last_billing_status?: string;
424
+ description?: string;
425
+ metadata?: Record<string, any>;
426
+ created_at: string;
427
+ updated_at: string;
428
+ }
429
+ /**
430
+ * Request to create a billing schedule
431
+ */
432
+ export interface CreateBillingScheduleRequest {
433
+ user_id?: string;
434
+ organization_id?: string;
435
+ schedule_type: ScheduleType;
436
+ amount_cents: number;
437
+ currency?: string;
438
+ interval_type: IntervalType;
439
+ interval_count?: number;
440
+ next_billing_date: string;
441
+ end_date?: string;
442
+ max_occurrences?: number;
443
+ payment_method_id?: string;
444
+ account_balance_id?: string;
445
+ auto_charge?: boolean;
446
+ send_invoice?: boolean;
447
+ retry_on_failure?: boolean;
448
+ max_retries?: number;
449
+ description?: string;
450
+ metadata?: Record<string, any>;
451
+ }
452
+ /**
453
+ * Request to update a billing schedule
454
+ */
455
+ export interface UpdateBillingScheduleRequest {
456
+ amount_cents?: number;
457
+ next_billing_date?: string;
458
+ end_date?: string;
459
+ max_occurrences?: number;
460
+ payment_method_id?: string;
461
+ account_balance_id?: string;
462
+ auto_charge?: boolean;
463
+ send_invoice?: boolean;
464
+ retry_on_failure?: boolean;
465
+ max_retries?: number;
466
+ description?: string;
467
+ metadata?: Record<string, any>;
468
+ }
469
+ /**
470
+ * Billing execution response
471
+ */
472
+ export interface BillingExecution {
473
+ id: string;
474
+ billing_schedule_id: string;
475
+ execution_date: string;
476
+ amount_cents: number;
477
+ currency: string;
478
+ status: string;
479
+ payment_id?: string;
480
+ receipt_id?: string;
481
+ error_message?: string;
482
+ retry_count: number;
483
+ created_at: string;
484
+ }
485
+ /**
486
+ * Balance type
487
+ */
488
+ export type BalanceType = 'general' | 'credits' | 'promotional' | 'refund';
489
+ /**
490
+ * Balance status
491
+ */
492
+ export type BalanceStatus = 'active' | 'suspended' | 'expired' | 'closed';
493
+ /**
494
+ * Transaction type
495
+ */
496
+ export type TransactionType = 'credit' | 'debit' | 'transfer' | 'expiration' | 'adjustment';
497
+ /**
498
+ * Account balance response
499
+ */
500
+ export interface AccountBalance {
501
+ id: string;
502
+ user_id?: string;
503
+ organization_id?: string;
504
+ customer_id?: string;
505
+ balance_cents: number;
506
+ currency: string;
507
+ balance_type: BalanceType;
508
+ reference_code?: string;
509
+ status: BalanceStatus;
510
+ expires_at?: string;
511
+ metadata?: Record<string, any>;
512
+ created_at: string;
513
+ updated_at: string;
514
+ }
515
+ /**
516
+ * Request to create an account balance
517
+ */
518
+ export interface CreateAccountBalanceRequest {
519
+ user_id?: string;
520
+ organization_id?: string;
521
+ customer_id?: string;
522
+ balance_type?: BalanceType;
523
+ balance_cents?: number;
524
+ currency?: string;
525
+ reference_code?: string;
526
+ expires_at?: string;
527
+ status?: BalanceStatus;
528
+ metadata?: Record<string, any>;
529
+ }
530
+ /**
531
+ * Request to update an account balance
532
+ */
533
+ export interface UpdateAccountBalanceRequest {
534
+ status?: BalanceStatus;
535
+ expires_at?: string;
536
+ metadata?: Record<string, any>;
537
+ }
538
+ /**
539
+ * Request to credit a balance
540
+ */
541
+ export interface CreditBalanceRequest {
542
+ amount_cents: number;
543
+ description?: string;
544
+ reference_code?: string;
545
+ }
546
+ /**
547
+ * Request to debit a balance
548
+ */
549
+ export interface DebitBalanceRequest {
550
+ amount_cents: number;
551
+ description?: string;
552
+ allow_negative?: boolean;
553
+ }
554
+ /**
555
+ * Account transaction response
556
+ */
557
+ export interface AccountTransaction {
558
+ id: string;
559
+ account_balance_id: string;
560
+ transaction_type: TransactionType;
561
+ amount_cents: number;
562
+ balance_before_cents: number;
563
+ balance_after_cents: number;
564
+ currency: string;
565
+ description?: string;
566
+ reference_code?: string;
567
+ status: string;
568
+ metadata?: Record<string, any>;
569
+ created_at: string;
570
+ }
571
+ /**
572
+ * Cost type
573
+ */
574
+ export type CostType = 'fixed' | 'per_unit' | 'per_hour' | 'percentage';
575
+ /**
576
+ * Product cost response
577
+ */
578
+ export interface ProductCost {
579
+ id: string;
580
+ product_id: string;
581
+ cost_type: CostType;
582
+ cost_cents: number;
583
+ currency: string;
584
+ effective_from: string;
585
+ effective_until?: string;
586
+ category?: string;
587
+ notes?: string;
588
+ metadata?: Record<string, any>;
589
+ created_at: string;
590
+ updated_at: string;
591
+ }
592
+ /**
593
+ * Request to create a product cost
594
+ */
595
+ export interface CreateProductCostRequest {
596
+ product_id: string;
597
+ cost_type: CostType;
598
+ cost_cents: number;
599
+ currency?: string;
600
+ effective_from?: string;
601
+ effective_until?: string;
602
+ category?: string;
603
+ notes?: string;
604
+ metadata?: Record<string, any>;
605
+ }
606
+ /**
607
+ * Request to update a product cost
608
+ */
609
+ export interface UpdateProductCostRequest {
610
+ cost_cents?: number;
611
+ effective_until?: string;
612
+ category?: string;
613
+ notes?: string;
614
+ metadata?: Record<string, any>;
615
+ }
616
+ /**
617
+ * Order cost response
618
+ */
619
+ export interface OrderCost {
620
+ id: string;
621
+ order_id: string;
622
+ cost_type: CostType;
623
+ cost_cents: number;
624
+ currency: string;
625
+ category?: string;
626
+ description?: string;
627
+ metadata?: Record<string, any>;
628
+ created_at: string;
629
+ }
630
+ /**
631
+ * Request to create an order cost
632
+ */
633
+ export interface CreateOrderCostRequest {
634
+ order_id: string;
635
+ cost_type: CostType;
636
+ cost_cents: number;
637
+ currency?: string;
638
+ category?: string;
639
+ description?: string;
640
+ metadata?: Record<string, any>;
641
+ }
642
+ /**
643
+ * Total cost response
644
+ */
645
+ export interface TotalCostResponse {
646
+ product_id?: string;
647
+ order_id?: string;
648
+ total_cost_cents: number;
649
+ total_cost_dollars: number;
650
+ calculated_at?: string;
651
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubflow/core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Core functionality for Pubflow framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,4 +43,4 @@
43
43
  "url": "https://github.com/pubflow/core/issues"
44
44
  },
45
45
  "homepage": "https://github.com/pubflow/core#readme"
46
- }
46
+ }