@happyvertical/smrt-affiliates 0.39.2 → 0.39.4

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/dist/index.d.ts CHANGED
@@ -1,995 +1,148 @@
1
- import { SmrtCollection } from '@happyvertical/smrt-core';
2
- import { SmrtObject } from '@happyvertical/smrt-core';
3
- import { SmrtObjectOptions } from '@happyvertical/smrt-core';
1
+ import { Commission } from '@happyvertical/smrt-sales';
2
+ import { CommissionCollection } from '@happyvertical/smrt-sales';
3
+ import { CommissionOptions as CommissionOptions_2 } from '@happyvertical/smrt-sales';
4
+ import { CommissionPayoutOptions } from '@happyvertical/smrt-sales';
5
+ import { EarnerOptions } from '@happyvertical/smrt-sales';
6
+ import { Earner as Partner } from '@happyvertical/smrt-sales';
7
+ import { EarnerCollection as PartnerCollection } from '@happyvertical/smrt-sales';
8
+ import { CommissionPayout as Payout } from '@happyvertical/smrt-sales';
9
+ import { CommissionPayoutCollection as PayoutCollection } from '@happyvertical/smrt-sales';
10
+
11
+ export { Commission }
12
+
13
+ export { CommissionCollection }
14
+
15
+ /** @deprecated Use `CommissionOptions` from `@happyvertical/smrt-sales`. */
16
+ export declare type CommissionOptions = CommissionOptions_2;
4
17
 
5
18
  /**
6
- * Commission tracks revenue attribution from ad events to partners.
7
- *
8
- * Each ad event can generate multiple commissions:
9
- * - Display commission to publisher (site owner)
10
- * - Referral commission to referrer (who brought in the publisher)
11
- * - Sales commission to salesperson (who brought in the advertiser)
12
- * - Parent commission to salesperson's parent publisher
19
+ * Legacy commission status values.
13
20
  *
14
- * References:
15
- * - eventId: String reference to smrt-ads AdEvent (cross-package)
16
- * - partnerId: FK to Partner (within package)
17
- * - payoutId: FK to Payout (within package)
18
- *
19
- * @example
20
- * ```typescript
21
- * // Create display commission for a publisher
22
- * const commission = await commissions.create({
23
- * eventId: 'adevent-uuid',
24
- * partnerId: publisher.id,
25
- * commissionType: CommissionType.DISPLAY,
26
- * grossRevenue: 100, // 1 cent = $0.01
27
- * commissionRate: 0.50,
28
- * commissionAmount: 50, // 0.5 cents
29
- * currency: 'CAD',
30
- * status: CommissionStatus.PENDING
31
- * });
32
- * ```
21
+ * @deprecated Use the `CommissionStatus` union
22
+ * (`'pending' | 'earned' | 'approved' | 'payable' | 'paid'`) from
23
+ * `@happyvertical/smrt-sales`. `PENDING` and `PAID` align; `INCLUDED` has no
24
+ * direct equivalent — the nearest new state is `'payable'` with `payoutId`
25
+ * set (a commission gathered into a payout batch). See MIGRATION.md.
33
26
  */
34
- export declare class Commission extends SmrtObject {
35
- /**
36
- * Calculate commission amount from gross revenue and rate
37
- *
38
- * @param grossRevenue - Gross revenue in cents
39
- * @param rate - Commission rate (0-1)
40
- * @returns Commission amount in cents (rounded)
41
- *
42
- * @example
43
- * ```typescript
44
- * const amount = Commission.calculateAmount(1000, 0.50); // 500 cents
45
- * ```
46
- */
47
- static calculateAmount(grossRevenue: number, rate: number): number;
48
- /**
49
- * Ad Event ID (FK to smrt-ads AdEvent, cross-package)
50
- */
51
- eventId: string;
52
- /**
53
- * Partner ID (FK to Partner)
54
- */
55
- partnerId: string;
56
- /**
57
- * Commission type (display, referral, sales, parent)
58
- */
59
- commissionType: CommissionType;
60
- /**
61
- * Gross revenue from the event in cents
62
- * This is the total ad revenue before commission split
63
- */
64
- grossRevenue: number;
65
- /**
66
- * Commission rate applied (0-1)
67
- * Copied from partner at time of event for audit trail
68
- */
69
- commissionRate: number;
70
- /**
71
- * Calculated commission amount in cents
72
- * = grossRevenue * commissionRate
73
- */
74
- commissionAmount: number;
75
- /**
76
- * Currency code
77
- * Defaults to CAD
78
- */
79
- currency: string;
80
- /**
81
- * Payout ID when commission is included in a payout
82
- */
83
- payoutId: string;
84
- /**
85
- * Commission status
86
- */
87
- status: CommissionStatus;
88
- /**
89
- * Event timestamp (copied from AdEvent for reporting)
90
- */
91
- eventTimestamp: Date;
92
- /**
93
- * Network ID for aggregate queries (optional context)
94
- */
95
- networkId: string;
96
- /**
97
- * Site/Property ID for aggregate queries (optional context)
98
- */
99
- siteId: string;
100
- /**
101
- * Campaign ID for aggregate queries (optional context)
102
- */
103
- campaignId: string;
104
- /**
105
- * Additional metadata as JSON string
106
- */
107
- metadata: string;
108
- constructor(options?: CommissionOptions);
109
- /**
110
- * Check if commission is pending (not yet in a payout)
111
- */
112
- isPending(): boolean;
113
- /**
114
- * Check if commission is included in a payout
115
- */
116
- isIncluded(): boolean;
117
- /**
118
- * Check if commission has been paid
119
- */
120
- isPaid(): boolean;
121
- /**
122
- * Check if this is a display commission
123
- */
124
- isDisplay(): boolean;
125
- /**
126
- * Check if this is a referral commission
127
- */
128
- isReferral(): boolean;
129
- /**
130
- * Check if this is a sales commission
131
- */
132
- isSales(): boolean;
133
- /**
134
- * Check if this is a parent commission
135
- */
136
- isParent(): boolean;
137
- /**
138
- * Check if this is an overhead commission
139
- */
140
- isOverhead(): boolean;
141
- /**
142
- * Get commission amount in dollars (for display)
143
- */
144
- getAmountInDollars(): number;
145
- /**
146
- * Get gross revenue in dollars (for display)
147
- */
148
- getGrossRevenueInDollars(): number;
149
- /**
150
- * Get metadata as object
151
- */
152
- getMetadata(): Record<string, unknown>;
153
- /**
154
- * Set metadata from object
155
- */
156
- setMetadata(data: Record<string, unknown>): void;
157
- }
27
+ export declare const CommissionStatus: Readonly<{
28
+ readonly PENDING: "pending";
29
+ readonly INCLUDED: "included";
30
+ readonly PAID: "paid";
31
+ }>;
158
32
 
159
- export declare class CommissionCollection extends SmrtCollection<Commission> {
160
- static readonly _itemClass: typeof Commission;
161
- /**
162
- * Find commissions by partner
163
- *
164
- * @param partnerId - Partner ID
165
- * @returns Array of commissions
166
- */
167
- findByPartner(partnerId: string): Promise<Commission[]>;
168
- /**
169
- * Find commissions by ad event
170
- *
171
- * @param eventId - Ad Event ID
172
- * @returns Array of commissions
173
- */
174
- findByEvent(eventId: string): Promise<Commission[]>;
175
- /**
176
- * Find commissions by payout
177
- *
178
- * @param payoutId - Payout ID
179
- * @returns Array of commissions
180
- */
181
- findByPayout(payoutId: string): Promise<Commission[]>;
182
- /**
183
- * Find commissions by status
184
- *
185
- * @param status - Commission status
186
- * @returns Array of commissions
187
- */
188
- findByStatus(status: CommissionStatus): Promise<Commission[]>;
189
- /**
190
- * Find all pending commissions
191
- */
192
- findPending(): Promise<Commission[]>;
193
- /**
194
- * Find pending commissions for a partner
195
- *
196
- * @param partnerId - Partner ID
197
- * @returns Array of pending commissions
198
- */
199
- findPendingByPartner(partnerId: string): Promise<Commission[]>;
200
- /**
201
- * Find commissions by type
202
- *
203
- * @param commissionType - Commission type
204
- * @returns Array of commissions
205
- */
206
- findByType(commissionType: CommissionType): Promise<Commission[]>;
207
- /**
208
- * Find commissions in date range
209
- *
210
- * @param start - Start date
211
- * @param end - End date
212
- * @returns Array of commissions
213
- */
214
- findByDateRange(start: Date, end: Date): Promise<Commission[]>;
215
- /**
216
- * Find commissions for a partner in date range
217
- *
218
- * @param partnerId - Partner ID
219
- * @param start - Start date
220
- * @param end - End date
221
- * @returns Array of commissions
222
- */
223
- findByPartnerAndDateRange(partnerId: string, start: Date, end: Date): Promise<Commission[]>;
224
- /**
225
- * Find all commissions for a network
226
- *
227
- * @param networkId - Network ID
228
- * @returns Array of commissions
229
- */
230
- findByNetwork(networkId: string): Promise<Commission[]>;
231
- /**
232
- * Find commissions for a network filtered by type
233
- *
234
- * @param networkId - Network ID
235
- * @param commissionType - Commission type
236
- * @returns Array of commissions
237
- */
238
- findByNetworkAndType(networkId: string, commissionType: CommissionType): Promise<Commission[]>;
239
- /**
240
- * Find pending commissions for a network
241
- *
242
- * @param networkId - Network ID
243
- * @returns Array of pending commissions
244
- */
245
- findPendingByNetwork(networkId: string): Promise<Commission[]>;
246
- /**
247
- * Get aggregate summary of commissions by type and site for a network.
248
- *
249
- * @param networkId - Network ID
250
- * @param options - Optional filters (siteId, from, to, commissionType)
251
- * @returns Summary with byType, bySite, total, and count
252
- */
253
- getSummaryByNetwork(networkId: string, options?: {
254
- siteId?: string;
255
- from?: Date;
256
- to?: Date;
257
- commissionType?: CommissionType;
258
- }): Promise<{
259
- byType: Record<string, number>;
260
- bySite: Record<string, number>;
261
- total: number;
262
- count: number;
263
- }>;
264
- /**
265
- * Get pending commissions grouped by partnerId for a network.
266
- *
267
- * @param networkId - Network ID
268
- * @returns Array of payout groups (partnerId, totalPending, currency, entries)
269
- */
270
- getPendingPayoutsByNetwork(networkId: string): Promise<Array<{
271
- partnerId: string;
272
- totalPending: number;
273
- currency: string;
274
- entryCount: number;
275
- entries: Array<{
276
- id: string;
277
- commissionType: string;
278
- commissionAmount: number;
279
- campaignId: string;
280
- siteId: string;
281
- }>;
282
- }>>;
283
- /**
284
- * Sum pending commissions for a partner
285
- *
286
- * @param partnerId - Partner ID
287
- * @returns Total pending amount in cents
288
- */
289
- sumPendingByPartner(partnerId: string): Promise<number>;
290
- /**
291
- * Sum commissions by type for a partner
292
- *
293
- * @param partnerId - Partner ID
294
- * @param commissionType - Commission type
295
- * @returns Total amount in cents
296
- */
297
- sumByPartnerAndType(partnerId: string, commissionType: CommissionType): Promise<number>;
298
- /**
299
- * Get earnings breakdown for a partner
300
- *
301
- * @param partnerId - Partner ID
302
- * @returns Breakdown by commission type
303
- */
304
- getEarningsBreakdown(partnerId: string): Promise<{
305
- display: number;
306
- referral: number;
307
- sales: number;
308
- parent: number;
309
- overhead: number;
310
- total: number;
311
- }>;
312
- /**
313
- * Get pending earnings breakdown for a partner
314
- *
315
- * @param partnerId - Partner ID
316
- * @returns Breakdown of pending commissions by type
317
- */
318
- getPendingBreakdown(partnerId: string): Promise<{
319
- display: number;
320
- referral: number;
321
- sales: number;
322
- parent: number;
323
- overhead: number;
324
- total: number;
325
- }>;
326
- }
33
+ /** @deprecated Use `CommissionStatus` from `@happyvertical/smrt-sales`. */
34
+ export declare type CommissionStatus = (typeof CommissionStatus)[keyof typeof CommissionStatus];
327
35
 
328
36
  /**
329
- * Options for constructing a {@link Commission}.
37
+ * Legacy commission type values.
38
+ *
39
+ * @deprecated Superseded by `CommissionPlan` component keys in
40
+ * `@happyvertical/smrt-sales`: a versioned plan's `components` array replaces
41
+ * the fixed display/referral/sales/parent/overhead taxonomy — each component
42
+ * has its own `key`, `trigger`, `basis`, and `rate`, and every `Commission`
43
+ * records the `componentKey` that produced it. See MIGRATION.md for a worked
44
+ * plan reproducing the legacy waterfall.
330
45
  */
331
- declare interface CommissionOptions extends SmrtObjectOptions {
332
- eventId?: string;
333
- partnerId?: string;
334
- commissionType?: CommissionType;
335
- grossRevenue?: number;
336
- commissionRate?: number;
337
- commissionAmount?: number;
338
- currency?: string;
339
- payoutId?: string;
340
- status?: CommissionStatus;
341
- eventTimestamp?: Date;
342
- networkId?: string;
343
- siteId?: string;
344
- campaignId?: string;
345
- metadata?: string;
346
- }
46
+ export declare const CommissionType: Readonly<{
47
+ readonly DISPLAY: "display";
48
+ readonly REFERRAL: "referral";
49
+ readonly SALES: "sales";
50
+ readonly PARENT: "parent";
51
+ readonly OVERHEAD: "overhead";
52
+ }>;
347
53
 
348
54
  /**
349
- * Commission status - lifecycle of a commission
55
+ * @deprecated Superseded by `CommissionPlan` component keys in
56
+ * `@happyvertical/smrt-sales`; see MIGRATION.md.
350
57
  */
351
- export declare enum CommissionStatus {
352
- PENDING = "pending",
353
- INCLUDED = "included",
354
- PAID = "paid"
355
- }
58
+ export declare type CommissionType = (typeof CommissionType)[keyof typeof CommissionType];
356
59
 
357
- /**
358
- * Commission types - how earnings were generated
359
- */
360
- export declare enum CommissionType {
361
- DISPLAY = "display",
362
- REFERRAL = "referral",
363
- SALES = "sales",
364
- PARENT = "parent",
365
- OVERHEAD = "overhead"
366
- }
60
+ export { Partner }
61
+
62
+ export { PartnerCollection }
63
+
64
+ /** @deprecated Use `EarnerOptions` from `@happyvertical/smrt-sales`. */
65
+ export declare type PartnerOptions = EarnerOptions;
367
66
 
368
67
  /**
369
- * Partner represents an entity that earns commissions from ad revenue.
370
- *
371
- * Partners can be:
372
- * - Publishers: Own sites that display ads (earn display commissions)
373
- * - Salespeople: Bring in advertisers (earn sales commissions)
374
- * - Referrers: Refer new publishers/partners (earn referral commissions)
68
+ * Legacy partner status values.
375
69
  *
376
- * References:
377
- * - profileId: String reference to smrt-profiles Profile (cross-package)
378
- * - propertyId: String reference to smrt-properties Property (cross-package)
379
- * - parentPartnerId: Self-reference for site-attached salespeople
380
- *
381
- * @example
382
- * ```typescript
383
- * // Create a publisher partner
384
- * const publisher = await partners.create({
385
- * profileId: 'profile-uuid',
386
- * propertyId: 'property-uuid',
387
- * partnerTypes: JSON.stringify([PartnerType.PUBLISHER]),
388
- * displayCommissionRate: 0.50,
389
- * status: PartnerStatus.ACTIVE
390
- * });
391
- *
392
- * // Create a salesperson attached to a publisher
393
- * const salesperson = await partners.create({
394
- * profileId: 'salesperson-profile-uuid',
395
- * parentPartnerId: publisher.id,
396
- * partnerTypes: JSON.stringify([PartnerType.SALESPERSON]),
397
- * salesCommissionRate: 0.10,
398
- * parentCommissionShare: 0.20,
399
- * status: PartnerStatus.ACTIVE
400
- * });
401
- * ```
70
+ * @deprecated Use the `EarnerStatus` union
71
+ * (`'pending' | 'active' | 'suspended'`) from `@happyvertical/smrt-sales` —
72
+ * the string values align exactly.
402
73
  */
403
- export declare class Partner extends SmrtObject {
404
- /**
405
- * Profile ID (FK to smrt-profiles Profile, cross-package)
406
- */
407
- profileId: string;
408
- /**
409
- * Property ID (FK to smrt-properties Property, cross-package)
410
- * Only set for publisher partners
411
- */
412
- propertyId: string;
413
- /**
414
- * Partner types as JSON array (publisher, salesperson, referrer)
415
- * A partner can have multiple types
416
- */
417
- partnerTypes: string;
418
- /**
419
- * Parent partner ID (self-reference)
420
- * For site-attached salespeople, this is the publisher they work under
421
- */
422
- parentPartnerId: string;
423
- /**
424
- * Referred by partner ID (self-reference)
425
- * Tracks who referred this partner for referral commission attribution
426
- */
427
- referredById: string;
428
- /**
429
- * Share of commission that goes to parent partner (0-1)
430
- * e.g., 0.20 means 20% of this partner's sales commission goes to parent
431
- */
432
- parentCommissionShare: number;
433
- /**
434
- * Commission rate for display (impression) revenue (0-1)
435
- * Default 50% - publisher earns half of ad impression revenue
436
- */
437
- displayCommissionRate: number;
438
- /**
439
- * Commission rate for referral revenue (0-1)
440
- * Default 5% - referrer earns 5% of referred partner's first-year revenue
441
- */
442
- referralCommissionRate: number;
443
- /**
444
- * Commission rate for sales revenue (0-1)
445
- * Default 10% - salesperson earns 10% of advertiser spend they brought in
446
- */
447
- salesCommissionRate: number;
448
- /**
449
- * Minimum payout threshold in cents
450
- * Default $50 = 5000 cents
451
- */
452
- payoutThreshold: number;
453
- /**
454
- * Preferred payout method
455
- */
456
- payoutMethod: PayoutMethod;
457
- /**
458
- * Currency code for all monetary values
459
- * Defaults to CAD, allows future multi-currency support
460
- */
461
- currency: string;
462
- /**
463
- * Partner status
464
- */
465
- status: PartnerStatus;
466
- /**
467
- * Additional metadata as JSON string
468
- * (bank details, tax info, etc.)
469
- */
470
- metadata: string;
471
- constructor(options?: PartnerOptions);
472
- /**
473
- * Get partner types as array
474
- */
475
- getPartnerTypes(): PartnerType[];
476
- /**
477
- * Set partner types from array
478
- */
479
- setPartnerTypes(types: PartnerType[]): void;
480
- /**
481
- * Check if partner has a specific type
482
- */
483
- hasType(type: PartnerType): boolean;
484
- /**
485
- * Check if partner is a publisher
486
- */
487
- isPublisher(): boolean;
488
- /**
489
- * Check if partner is a salesperson
490
- */
491
- isSalesperson(): boolean;
492
- /**
493
- * Check if partner is a referrer
494
- */
495
- isReferrer(): boolean;
496
- /**
497
- * Check if partner is active
498
- */
499
- isActive(): boolean;
500
- /**
501
- * Check if partner is pending approval
502
- */
503
- isPending(): boolean;
504
- /**
505
- * Check if partner is suspended
506
- */
507
- isSuspended(): boolean;
508
- /**
509
- * Check if partner has a parent (site-attached)
510
- */
511
- hasParent(): boolean;
512
- /**
513
- * Check if partner was referred by another partner
514
- */
515
- wasReferred(): boolean;
516
- /**
517
- * Get metadata as object
518
- */
519
- getMetadata(): Record<string, unknown>;
520
- /**
521
- * Set metadata from object
522
- */
523
- setMetadata(data: Record<string, unknown>): void;
524
- /**
525
- * Calculate effective sales commission rate (after parent share)
526
- */
527
- getEffectiveSalesRate(): number;
528
- }
74
+ export declare const PartnerStatus: Readonly<{
75
+ readonly PENDING: "pending";
76
+ readonly ACTIVE: "active";
77
+ readonly SUSPENDED: "suspended";
78
+ }>;
529
79
 
530
- export declare class PartnerCollection extends SmrtCollection<Partner> {
531
- static readonly _itemClass: typeof Partner;
532
- /**
533
- * Find partners by profile ID
534
- *
535
- * @param profileId - Profile ID
536
- * @returns Array of partners
537
- */
538
- findByProfile(profileId: string): Promise<Partner[]>;
539
- /**
540
- * Find partner by property ID (publishers)
541
- *
542
- * @param propertyId - Property ID
543
- * @returns Partner or null
544
- */
545
- findByProperty(propertyId: string): Promise<Partner | null>;
546
- /**
547
- * Find partners by parent partner ID
548
- *
549
- * @param parentPartnerId - Parent partner ID
550
- * @returns Array of child partners
551
- */
552
- findByParent(parentPartnerId: string): Promise<Partner[]>;
553
- /**
554
- * Find partners referred by a specific partner
555
- *
556
- * @param referredById - Referrer partner ID
557
- * @returns Array of referred partners
558
- */
559
- findByReferrer(referredById: string): Promise<Partner[]>;
560
- /**
561
- * Find partners by status
562
- *
563
- * @param status - Partner status
564
- * @returns Array of partners
565
- */
566
- findByStatus(status: PartnerStatus): Promise<Partner[]>;
567
- /**
568
- * Find all active partners
569
- */
570
- findActive(): Promise<Partner[]>;
571
- /**
572
- * Find all pending partners (awaiting approval)
573
- */
574
- findPending(): Promise<Partner[]>;
575
- /**
576
- * Find all suspended partners
577
- */
578
- findSuspended(): Promise<Partner[]>;
579
- /**
580
- * Find partners by type (requires in-memory filtering for JSON field)
581
- *
582
- * @param type - Partner type to filter by
583
- * @returns Array of partners with that type
584
- */
585
- findByType(type: PartnerType): Promise<Partner[]>;
586
- /**
587
- * Find all publisher partners
588
- */
589
- findPublishers(): Promise<Partner[]>;
590
- /**
591
- * Find all salesperson partners
592
- */
593
- findSalespeople(): Promise<Partner[]>;
594
- /**
595
- * Find all referrer partners
596
- */
597
- findReferrers(): Promise<Partner[]>;
598
- /**
599
- * Find active publishers (for ad serving)
600
- */
601
- findActivePublishers(): Promise<Partner[]>;
602
- /**
603
- * Find partner for ad serving by property ID
604
- * Returns active publisher partner for the property
605
- *
606
- * @param propertyId - Property ID
607
- * @returns Active publisher partner or null
608
- */
609
- findActiveByProperty(propertyId: string): Promise<Partner | null>;
610
- /**
611
- * Find partners eligible for payout
612
- * (active partners with pending commissions above threshold)
613
- * Note: Actual threshold check requires joining with commissions
614
- */
615
- findEligibleForPayout(): Promise<Partner[]>;
616
- }
80
+ /** @deprecated Use `EarnerStatus` from `@happyvertical/smrt-sales`. */
81
+ export declare type PartnerStatus = (typeof PartnerStatus)[keyof typeof PartnerStatus];
617
82
 
618
83
  /**
619
- * Options for constructing a {@link Partner}.
84
+ * Legacy partner role values.
85
+ *
86
+ * @deprecated Partner roles have NO direct equivalent in
87
+ * `@happyvertical/smrt-sales` — roles are now first-class models instead of a
88
+ * JSON array on the financial account: use `Referrer` from
89
+ * `@happyvertical/smrt-sales/referrals` and `SalesRepresentative` from
90
+ * `@happyvertical/smrt-sales/crm` (each holds an `earnerId`); model
91
+ * publisher-style roles in your application domain. See MIGRATION.md.
620
92
  */
621
- declare interface PartnerOptions extends SmrtObjectOptions {
622
- profileId?: string;
623
- propertyId?: string;
624
- partnerTypes?: string;
625
- parentPartnerId?: string;
626
- referredById?: string;
627
- parentCommissionShare?: number;
628
- displayCommissionRate?: number;
629
- referralCommissionRate?: number;
630
- salesCommissionRate?: number;
631
- payoutThreshold?: number;
632
- payoutMethod?: PayoutMethod;
633
- currency?: string;
634
- status?: PartnerStatus;
635
- metadata?: string;
636
- }
93
+ export declare const PartnerType: Readonly<{
94
+ readonly PUBLISHER: "publisher";
95
+ readonly SALESPERSON: "salesperson";
96
+ readonly REFERRER: "referrer";
97
+ }>;
637
98
 
638
99
  /**
639
- * Partner status
100
+ * @deprecated Roles are first-class models in `@happyvertical/smrt-sales`
101
+ * (`Referrer`, `SalesRepresentative`); see MIGRATION.md.
640
102
  */
641
- export declare enum PartnerStatus {
642
- PENDING = "pending",
643
- ACTIVE = "active",
644
- SUSPENDED = "suspended"
645
- }
103
+ export declare type PartnerType = (typeof PartnerType)[keyof typeof PartnerType];
646
104
 
647
- /**
648
- * Types and enums for smrt-affiliates package
649
- */
650
- /**
651
- * Partner types - what role(s) this partner plays
652
- */
653
- export declare enum PartnerType {
654
- PUBLISHER = "publisher",
655
- SALESPERSON = "salesperson",
656
- REFERRER = "referrer"
657
- }
105
+ export { Payout }
106
+
107
+ export { PayoutCollection }
658
108
 
659
109
  /**
660
- * Payout represents an aggregated payment batch for a partner.
661
- *
662
- * Payouts are created periodically (e.g., monthly) and include
663
- * all pending commissions for a partner that meet the threshold.
664
- *
665
- * References:
666
- * - partnerId: FK to Partner (within package)
667
- * - invoiceId: String reference to smrt-commerce Invoice (cross-package)
110
+ * Legacy payout method values.
668
111
  *
669
- * @example
670
- * ```typescript
671
- * // Create a payout for a partner
672
- * const payout = await payouts.create({
673
- * partnerId: publisher.id,
674
- * periodStart: new Date('2024-01-01'),
675
- * periodEnd: new Date('2024-01-31'),
676
- * displayEarnings: 25000, // $250.00
677
- * referralEarnings: 500, // $5.00
678
- * salesEarnings: 0,
679
- * parentEarnings: 0,
680
- * totalAmount: 25500, // $255.00
681
- * currency: 'CAD',
682
- * status: PayoutStatus.PENDING
683
- * });
684
- * ```
112
+ * @deprecated Use the `PayoutMethod` union
113
+ * (`'bank_transfer' | 'check' | 'paypal' | 'credit' | 'other'`) from
114
+ * `@happyvertical/smrt-sales` — the legacy values align exactly; the new
115
+ * union adds `'other'`.
685
116
  */
686
- export declare class Payout extends SmrtObject {
687
- /**
688
- * Partner ID (FK to Partner)
689
- */
690
- partnerId: string;
691
- /**
692
- * Period start date
693
- */
694
- periodStart: Date;
695
- /**
696
- * Period end date
697
- */
698
- periodEnd: Date;
699
- /**
700
- * Total display earnings in cents
701
- */
702
- displayEarnings: number;
703
- /**
704
- * Total referral earnings in cents
705
- */
706
- referralEarnings: number;
707
- /**
708
- * Total sales earnings in cents
709
- */
710
- salesEarnings: number;
711
- /**
712
- * Total parent earnings in cents (from site-attached salespeople)
713
- */
714
- parentEarnings: number;
715
- /**
716
- * Total overhead earnings in cents (network overhead commissions)
717
- */
718
- overheadEarnings: number;
719
- /**
720
- * Total payout amount in cents
721
- * = displayEarnings + referralEarnings + salesEarnings + parentEarnings + overheadEarnings
722
- */
723
- totalAmount: number;
724
- /**
725
- * Currency code
726
- * Defaults to CAD
727
- */
728
- currency: string;
729
- /**
730
- * Invoice ID when payout is processed (FK to smrt-commerce Invoice)
731
- * Partner is treated as a Vendor for payout invoices
732
- */
733
- invoiceId: string;
734
- /**
735
- * Payout status
736
- */
737
- status: PayoutStatus;
738
- /**
739
- * Payment reference (check number, transfer ID, etc.)
740
- */
741
- paymentReference: string;
742
- /**
743
- * Date payment was processed
744
- */
745
- paidAt: Date | null;
746
- /**
747
- * Notes from admin (approval notes, issues, etc.)
748
- */
749
- notes: string;
750
- /**
751
- * Additional metadata as JSON string
752
- */
753
- metadata: string;
754
- constructor(options?: PayoutOptions);
755
- /**
756
- * Check if payout is pending approval
757
- */
758
- isPending(): boolean;
759
- /**
760
- * Check if payout is approved (waiting for processing)
761
- */
762
- isApproved(): boolean;
763
- /**
764
- * Check if payout is being processed
765
- */
766
- isProcessing(): boolean;
767
- /**
768
- * Check if payout is completed
769
- */
770
- isCompleted(): boolean;
771
- /**
772
- * Check if payout failed
773
- */
774
- isFailed(): boolean;
775
- /**
776
- * Get total amount in dollars (for display)
777
- */
778
- getTotalInDollars(): number;
779
- /**
780
- * Get display earnings in dollars
781
- */
782
- getDisplayEarningsInDollars(): number;
783
- /**
784
- * Get referral earnings in dollars
785
- */
786
- getReferralEarningsInDollars(): number;
787
- /**
788
- * Get sales earnings in dollars
789
- */
790
- getSalesEarningsInDollars(): number;
791
- /**
792
- * Get parent earnings in dollars
793
- */
794
- getParentEarningsInDollars(): number;
795
- /**
796
- * Get overhead earnings in dollars
797
- */
798
- getOverheadEarningsInDollars(): number;
799
- /**
800
- * Calculate total from component earnings
801
- */
802
- calculateTotal(): number;
803
- /**
804
- * Get period as human-readable string
805
- */
806
- getPeriodString(): string;
807
- /**
808
- * Get metadata as object
809
- */
810
- getMetadata(): Record<string, unknown>;
811
- /**
812
- * Set metadata from object
813
- */
814
- setMetadata(data: Record<string, unknown>): void;
815
- /**
816
- * Approve the payout for processing
817
- *
818
- * @throws Error if payout is not in pending status
819
- */
820
- approve(): void;
821
- /**
822
- * Mark payout as processing (payment in progress)
823
- *
824
- * @throws Error if payout is not in approved status
825
- */
826
- markProcessing(): void;
827
- /**
828
- * Mark payout as completed
829
- *
830
- * @param paymentReference - Payment reference (check number, transfer ID, etc.)
831
- * @throws Error if payout is not in processing status
832
- */
833
- complete(paymentReference: string): void;
834
- /**
835
- * Mark payout as failed
836
- *
837
- * @param reason - Reason for failure (stored in notes)
838
- */
839
- fail(reason: string): void;
840
- }
117
+ export declare const PayoutMethod: Readonly<{
118
+ readonly BANK_TRANSFER: "bank_transfer";
119
+ readonly CHECK: "check";
120
+ readonly PAYPAL: "paypal";
121
+ readonly CREDIT: "credit";
122
+ }>;
841
123
 
842
- export declare class PayoutCollection extends SmrtCollection<Payout> {
843
- static readonly _itemClass: typeof Payout;
844
- /**
845
- * Find payouts by partner
846
- *
847
- * @param partnerId - Partner ID
848
- * @returns Array of payouts
849
- */
850
- findByPartner(partnerId: string): Promise<Payout[]>;
851
- /**
852
- * Find payouts by status
853
- *
854
- * @param status - Payout status
855
- * @returns Array of payouts
856
- */
857
- findByStatus(status: PayoutStatus): Promise<Payout[]>;
858
- /**
859
- * Find all pending payouts (awaiting approval)
860
- */
861
- findPending(): Promise<Payout[]>;
862
- /**
863
- * Find all approved payouts (ready for processing)
864
- */
865
- findApproved(): Promise<Payout[]>;
866
- /**
867
- * Find all processing payouts
868
- */
869
- findProcessing(): Promise<Payout[]>;
870
- /**
871
- * Find all completed payouts
872
- */
873
- findCompleted(): Promise<Payout[]>;
874
- /**
875
- * Find all failed payouts
876
- */
877
- findFailed(): Promise<Payout[]>;
878
- /**
879
- * Find payouts by invoice
880
- *
881
- * @param invoiceId - Invoice ID
882
- * @returns Array of payouts
883
- */
884
- findByInvoice(invoiceId: string): Promise<Payout[]>;
885
- /**
886
- * Find payouts in period range
887
- *
888
- * @param start - Period start date
889
- * @param end - Period end date
890
- * @returns Array of payouts
891
- */
892
- findByPeriod(start: Date, end: Date): Promise<Payout[]>;
893
- /**
894
- * Find payouts for a partner by status
895
- *
896
- * @param partnerId - Partner ID
897
- * @param status - Payout status
898
- * @returns Array of payouts
899
- */
900
- findByPartnerAndStatus(partnerId: string, status: PayoutStatus): Promise<Payout[]>;
901
- /**
902
- * Find pending payouts for a partner
903
- *
904
- * @param partnerId - Partner ID
905
- * @returns Array of pending payouts
906
- */
907
- findPendingByPartner(partnerId: string): Promise<Payout[]>;
908
- /**
909
- * Find completed payouts for a partner
910
- *
911
- * @param partnerId - Partner ID
912
- * @returns Array of completed payouts
913
- */
914
- findCompletedByPartner(partnerId: string): Promise<Payout[]>;
915
- /**
916
- * Sum total paid to a partner
917
- *
918
- * @param partnerId - Partner ID
919
- * @returns Total paid in cents
920
- */
921
- sumPaidByPartner(partnerId: string): Promise<number>;
922
- /**
923
- * Sum total pending for a partner
924
- *
925
- * @param partnerId - Partner ID
926
- * @returns Total pending in cents
927
- */
928
- sumPendingByPartner(partnerId: string): Promise<number>;
929
- /**
930
- * Get most recent payout for a partner
931
- *
932
- * @param partnerId - Partner ID
933
- * @returns Most recent payout or null
934
- */
935
- findLatestByPartner(partnerId: string): Promise<Payout | null>;
936
- /**
937
- * Get payout statistics
938
- *
939
- * @returns Stats object
940
- */
941
- getStats(): Promise<{
942
- pending: number;
943
- approved: number;
944
- processing: number;
945
- completed: number;
946
- failed: number;
947
- totalPaid: number;
948
- totalPending: number;
949
- }>;
950
- }
124
+ /** @deprecated Use `PayoutMethod` from `@happyvertical/smrt-sales`. */
125
+ export declare type PayoutMethod = (typeof PayoutMethod)[keyof typeof PayoutMethod];
951
126
 
952
- /**
953
- * Payout method - how payment is delivered
954
- */
955
- export declare enum PayoutMethod {
956
- BANK_TRANSFER = "bank_transfer",
957
- CHECK = "check",
958
- PAYPAL = "paypal",
959
- CREDIT = "credit"
960
- }
961
-
962
- /**
963
- * Options for constructing a {@link Payout}.
964
- */
965
- declare interface PayoutOptions extends SmrtObjectOptions {
966
- partnerId?: string;
967
- periodStart?: Date;
968
- periodEnd?: Date;
969
- displayEarnings?: number;
970
- referralEarnings?: number;
971
- salesEarnings?: number;
972
- parentEarnings?: number;
973
- overheadEarnings?: number;
974
- totalAmount?: number;
975
- currency?: string;
976
- invoiceId?: string;
977
- status?: PayoutStatus;
978
- paymentReference?: string;
979
- paidAt?: Date | null;
980
- notes?: string;
981
- metadata?: string;
982
- }
127
+ /** @deprecated Use `CommissionPayoutOptions` from `@happyvertical/smrt-sales`. */
128
+ export declare type PayoutOptions = CommissionPayoutOptions;
983
129
 
984
130
  /**
985
- * Payout status - lifecycle of a payout batch
131
+ * Legacy payout status values.
132
+ *
133
+ * @deprecated Use the `CommissionPayoutStatus` union
134
+ * (`'pending' | 'approved' | 'processing' | 'completed' | 'failed'`) from
135
+ * `@happyvertical/smrt-sales` — the string values align exactly.
986
136
  */
987
- export declare enum PayoutStatus {
988
- PENDING = "pending",
989
- APPROVED = "approved",
990
- PROCESSING = "processing",
991
- COMPLETED = "completed",
992
- FAILED = "failed"
993
- }
137
+ export declare const PayoutStatus: Readonly<{
138
+ readonly PENDING: "pending";
139
+ readonly APPROVED: "approved";
140
+ readonly PROCESSING: "processing";
141
+ readonly COMPLETED: "completed";
142
+ readonly FAILED: "failed";
143
+ }>;
144
+
145
+ /** @deprecated Use `CommissionPayoutStatus` from `@happyvertical/smrt-sales`. */
146
+ export declare type PayoutStatus = (typeof PayoutStatus)[keyof typeof PayoutStatus];
994
147
 
995
148
  export { }