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