@etohq/ambassador 1.5.1-alpha.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.
Files changed (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +8 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/models/ambassador.d.ts +39 -0
  8. package/dist/models/ambassador.d.ts.map +1 -0
  9. package/dist/models/ambassador.js +67 -0
  10. package/dist/models/ambassador.js.map +1 -0
  11. package/dist/models/commission.d.ts +23 -0
  12. package/dist/models/commission.d.ts.map +1 -0
  13. package/dist/models/commission.js +93 -0
  14. package/dist/models/commission.js.map +1 -0
  15. package/dist/models/index.d.ts +8 -0
  16. package/dist/models/index.d.ts.map +1 -0
  17. package/dist/models/index.js +18 -0
  18. package/dist/models/index.js.map +1 -0
  19. package/dist/models/partner.d.ts +38 -0
  20. package/dist/models/partner.d.ts.map +1 -0
  21. package/dist/models/partner.js +78 -0
  22. package/dist/models/partner.js.map +1 -0
  23. package/dist/models/payout.d.ts +28 -0
  24. package/dist/models/payout.d.ts.map +1 -0
  25. package/dist/models/payout.js +57 -0
  26. package/dist/models/payout.js.map +1 -0
  27. package/dist/models/program-enrollment.d.ts +26 -0
  28. package/dist/models/program-enrollment.d.ts.map +1 -0
  29. package/dist/models/program-enrollment.js +81 -0
  30. package/dist/models/program-enrollment.js.map +1 -0
  31. package/dist/models/program.d.ts +52 -0
  32. package/dist/models/program.d.ts.map +1 -0
  33. package/dist/models/program.js +106 -0
  34. package/dist/models/program.js.map +1 -0
  35. package/dist/models/revenue-share-rule.d.ts +25 -0
  36. package/dist/models/revenue-share-rule.d.ts.map +1 -0
  37. package/dist/models/revenue-share-rule.js +54 -0
  38. package/dist/models/revenue-share-rule.js.map +1 -0
  39. package/dist/models/reward.d.ts +16 -0
  40. package/dist/models/reward.d.ts.map +1 -0
  41. package/dist/models/reward.js +41 -0
  42. package/dist/models/reward.js.map +1 -0
  43. package/dist/services/ambassador-module-service.d.ts +221 -0
  44. package/dist/services/ambassador-module-service.d.ts.map +1 -0
  45. package/dist/services/ambassador-module-service.js +972 -0
  46. package/dist/services/ambassador-module-service.js.map +1 -0
  47. package/dist/services/ambassador-service.d.ts +57 -0
  48. package/dist/services/ambassador-service.d.ts.map +1 -0
  49. package/dist/services/ambassador-service.js +127 -0
  50. package/dist/services/ambassador-service.js.map +1 -0
  51. package/dist/services/commission-service.d.ts +45 -0
  52. package/dist/services/commission-service.d.ts.map +1 -0
  53. package/dist/services/commission-service.js +146 -0
  54. package/dist/services/commission-service.js.map +1 -0
  55. package/dist/services/index.d.ts +2 -0
  56. package/dist/services/index.d.ts.map +1 -0
  57. package/dist/services/index.js +9 -0
  58. package/dist/services/index.js.map +1 -0
  59. package/dist/services/payout-service.d.ts +35 -0
  60. package/dist/services/payout-service.d.ts.map +1 -0
  61. package/dist/services/payout-service.js +87 -0
  62. package/dist/services/payout-service.js.map +1 -0
  63. package/dist/services/program-enrollment-service.d.ts +39 -0
  64. package/dist/services/program-enrollment-service.d.ts.map +1 -0
  65. package/dist/services/program-enrollment-service.js +102 -0
  66. package/dist/services/program-enrollment-service.js.map +1 -0
  67. package/dist/services/program-service.d.ts +78 -0
  68. package/dist/services/program-service.d.ts.map +1 -0
  69. package/dist/services/program-service.js +180 -0
  70. package/dist/services/program-service.js.map +1 -0
  71. package/dist/services/revenue-rule-resolver.d.ts +15 -0
  72. package/dist/services/revenue-rule-resolver.d.ts.map +1 -0
  73. package/dist/services/revenue-rule-resolver.js +836 -0
  74. package/dist/services/revenue-rule-resolver.js.map +1 -0
  75. package/dist/services/revenue-share-rule-service.d.ts +5 -0
  76. package/dist/services/revenue-share-rule-service.d.ts.map +1 -0
  77. package/dist/services/revenue-share-rule-service.js +8 -0
  78. package/dist/services/revenue-share-rule-service.js.map +1 -0
  79. package/dist/services/reward-service.d.ts +31 -0
  80. package/dist/services/reward-service.d.ts.map +1 -0
  81. package/dist/services/reward-service.js +82 -0
  82. package/dist/services/reward-service.js.map +1 -0
  83. package/dist/tsconfig.tsbuildinfo +1 -0
  84. package/dist/utils/analytics.d.ts +19 -0
  85. package/dist/utils/analytics.d.ts.map +1 -0
  86. package/dist/utils/analytics.js +90 -0
  87. package/dist/utils/analytics.js.map +1 -0
  88. package/dist/utils/sustainability-monitor.d.ts +20 -0
  89. package/dist/utils/sustainability-monitor.d.ts.map +1 -0
  90. package/dist/utils/sustainability-monitor.js +46 -0
  91. package/dist/utils/sustainability-monitor.js.map +1 -0
  92. package/dist/workflows/calculate-commission-workflow.d.ts +2 -0
  93. package/dist/workflows/calculate-commission-workflow.d.ts.map +1 -0
  94. package/dist/workflows/calculate-commission-workflow.js +59 -0
  95. package/dist/workflows/calculate-commission-workflow.js.map +1 -0
  96. package/dist/workflows/steps/index.d.ts +2 -0
  97. package/dist/workflows/steps/index.d.ts.map +1 -0
  98. package/dist/workflows/steps/index.js +158 -0
  99. package/dist/workflows/steps/index.js.map +1 -0
  100. package/package.json +56 -0
@@ -0,0 +1,972 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const utils_1 = require("@etohq/framework/utils");
16
+ const analytics_1 = require("../utils/analytics");
17
+ const models_1 = require("../models");
18
+ const generatedModels = {
19
+ Ambassador: models_1.Ambassador,
20
+ Program: models_1.Program,
21
+ Commission: models_1.Commission,
22
+ Reward: models_1.Reward,
23
+ ProgramEnrollment: models_1.ProgramEnrollment,
24
+ RevenueShareRule: models_1.RevenueShareRule,
25
+ Payout: models_1.Payout
26
+ };
27
+ class AmbassadorModuleService extends utils_1.ModulesSdkUtils.EtoService(generatedModels) {
28
+ constructor(dependencies, moduleDeclaration) {
29
+ // @ts-ignore
30
+ super(...arguments);
31
+ this.moduleDeclaration = moduleDeclaration;
32
+ this.baseRepository_ = dependencies.baseRepository;
33
+ this.ambassadorService_ = dependencies.ambassadorService;
34
+ this.programService_ = dependencies.programService;
35
+ this.commissionService_ = dependencies.commissionService;
36
+ this.rewardService_ = dependencies.rewardService;
37
+ this.payoutService_ = dependencies.payoutService;
38
+ this.programEnrollmentService_ = dependencies.programEnrollmentService;
39
+ this.revenueShareRuleService_ = dependencies.revenueShareRuleService;
40
+ this.revenueRuleResolver_ = dependencies.revenueRuleResolver;
41
+ }
42
+ // ===== AMBASSADOR METHODS (Step 2.1 Requirements) =====
43
+ async createAmbassador(sourceType, sourceId, data, sharedContext = {}) {
44
+ return await this.ambassadorService_.createAmbassador(sourceType, sourceId, data, sharedContext);
45
+ }
46
+ async getAmbassadorBySource(sourceType, sourceId, sharedContext = {}) {
47
+ return await this.ambassadorService_.getAmbassadorBySource(sourceType, sourceId, sharedContext);
48
+ }
49
+ // @ts-expect-error
50
+ async listAmbassadors(filters, config = {}, sharedContext = {}) {
51
+ return await this.ambassadorService_.list(filters, config, sharedContext);
52
+ }
53
+ async verifyWebsite(ambassadorId, domain, sharedContext = {}) {
54
+ return await this.ambassadorService_.verifyWebsite(ambassadorId, domain, sharedContext);
55
+ }
56
+ async verifyYoutube(ambassadorId, channelId, sharedContext = {}) {
57
+ return await this.ambassadorService_.verifyYoutube(ambassadorId, channelId, sharedContext);
58
+ }
59
+ // @InjectTransactionManager()
60
+ // async updatePayoutSettings(
61
+ // ambassadorId: string,
62
+ // settings: PayoutSettingsDTO,
63
+ // @EtoContext() sharedContext: Context = {}
64
+ // ): Promise<AmbassadorDTO> {
65
+ // return await this.ambassadorService_.updatePayoutSettings(
66
+ // ambassadorId,
67
+ // settings,
68
+ // sharedContext
69
+ // )
70
+ // }
71
+ // ===== PROGRAM METHODS (Delegated to Program Service) =====
72
+ async createProgram(data, sharedContext = {}) {
73
+ return await this.programService_.createProgramWithValidation(data, sharedContext);
74
+ }
75
+ async getProgramOrThrow(programId, ownerId, ownerType, sharedContext = {}) {
76
+ return await this.programService_.getProgramOrThrow(programId, ownerId, ownerType, sharedContext);
77
+ }
78
+ async listProgramsByOwner(ownerId, ownerType, filters = {}, config = {}, sharedContext = {}) {
79
+ return await this.programService_.listProgramsByOwner(ownerId, ownerType, filters, config, sharedContext);
80
+ }
81
+ async updateProgram(data, sharedContext = {}) {
82
+ return await this.programService_.updateProgramWithValidation(data, sharedContext);
83
+ }
84
+ // ===== ENROLLMENT METHODS (Direct Enrollment) =====
85
+ async enrollAmbassador(data, sharedContext = {}) {
86
+ // Get program to check auto-approval
87
+ const program = await this.programService_.getProgramOrThrow(data.program_id, undefined, undefined, sharedContext);
88
+ return await this.programEnrollmentService_.enrollAmbassador(data, program.auto_approve_ambassadors, sharedContext);
89
+ }
90
+ async approveEnrollment(enrollmentId, sharedContext = {}) {
91
+ return await this.programEnrollmentService_.updateEnrollmentStatus(enrollmentId, "approved", sharedContext);
92
+ }
93
+ async getEnrollmentOrThrow(ambassadorId, programId, sharedContext = {}) {
94
+ return await this.programEnrollmentService_.getEnrollmentOrThrow(ambassadorId, programId, sharedContext);
95
+ }
96
+ async listEnrollmentsByProgram(programId, filters = {}, config = {}, sharedContext = {}) {
97
+ return await this.programEnrollmentService_.getEnrollmentsByProgram(programId, filters, config, sharedContext);
98
+ }
99
+ async calculateEarnings(programId, eventType, amount, sharedContext = {}) {
100
+ const program = await this.programService_.retrieve(programId, {}, sharedContext);
101
+ // @ts-ignore
102
+ const reward = program.rewards?.find((r) => r.event_type === eventType);
103
+ if (!reward) {
104
+ return { amount: 0, calculation_type: "no_reward" };
105
+ }
106
+ let earnings = 0;
107
+ if (reward.type === "percentage") {
108
+ earnings = Math.round((amount * reward.amount) / 100);
109
+ }
110
+ else if (reward.type === "flat") {
111
+ earnings = reward.amount;
112
+ }
113
+ return {
114
+ amount: earnings,
115
+ calculation_type: reward.type,
116
+ };
117
+ }
118
+ // ===== REWARD MANAGEMENT (Dub Parity) =====
119
+ // @ts-expect-error
120
+ async createReward(data, sharedContext = {}) {
121
+ return await this.rewardService_.create(data, sharedContext);
122
+ }
123
+ // @ts-expect-error
124
+ async listRewards(filters = {}, config = {}, sharedContext = {}) {
125
+ return await this.rewardService_.list(filters, config, sharedContext);
126
+ }
127
+ // @ts-expect-error
128
+ async retrieveReward(id, config = {}, sharedContext = {}) {
129
+ return await this.rewardService_.retrieve(id, config, sharedContext);
130
+ }
131
+ async updateReward(id, data, sharedContext = {}) {
132
+ return await this.rewardService_.update({ ...data, id }, sharedContext);
133
+ }
134
+ async deleteReward(id, sharedContext = {}) {
135
+ return await this.rewardService_.delete(id, sharedContext);
136
+ }
137
+ // ===== REVENUE RULE MANAGEMENT =====
138
+ async createRevenueRule(data, sharedContext = {}) {
139
+ // Validate shares total 100%
140
+ const total = data.actor_share +
141
+ data.context_owner_share +
142
+ data.creator_share +
143
+ data.beneficiary_share +
144
+ data.platform_share;
145
+ if (Math.abs(total - 100) > 0.01) {
146
+ throw new utils_1.EtoError(utils_1.EtoError.Types.INVALID_ARGUMENT, `Revenue shares must total 100%, got ${total}%`);
147
+ }
148
+ // Validate minimum platform share for sustainability
149
+ if (data.platform_share < 0) {
150
+ throw new utils_1.EtoError(utils_1.EtoError.Types.INVALID_ARGUMENT, `Platform share cannot be negative, got ${data.platform_share}%`);
151
+ }
152
+ return await this.revenueShareRuleService_.create(data, sharedContext);
153
+ }
154
+ async listRevenueRules(filters = {}, config = {}, sharedContext = {}) {
155
+ return await this.revenueShareRuleService_.list(filters, config, sharedContext);
156
+ }
157
+ async retrieveRevenueRule(id, config = {}, sharedContext = {}) {
158
+ return await this.revenueShareRuleService_.retrieve(id, config, sharedContext);
159
+ }
160
+ async updateRevenueRule(id, data, sharedContext = {}) {
161
+ // If updating shares, validate they total 100%
162
+ if (data.actor_share !== undefined ||
163
+ data.context_owner_share !== undefined ||
164
+ data.creator_share !== undefined ||
165
+ data.beneficiary_share !== undefined ||
166
+ data.platform_share !== undefined) {
167
+ // Get current rule to fill in missing values
168
+ const currentRule = await this.revenueShareRuleService_.retrieve(id, {}, sharedContext);
169
+ const total = (data.actor_share ?? currentRule.actor_share) +
170
+ (data.context_owner_share ?? currentRule.context_owner_share) +
171
+ (data.creator_share ?? currentRule.creator_share) +
172
+ (data.beneficiary_share ?? currentRule.beneficiary_share) +
173
+ (data.platform_share ?? currentRule.platform_share);
174
+ if (Math.abs(total - 100) > 0.01) {
175
+ throw new utils_1.EtoError(utils_1.EtoError.Types.INVALID_ARGUMENT, `Revenue shares must total 100%, got ${total}%`);
176
+ }
177
+ const platformShare = data.platform_share ?? currentRule.platform_share;
178
+ if (platformShare < 0) {
179
+ throw new utils_1.EtoError(utils_1.EtoError.Types.INVALID_ARGUMENT, `Platform share cannot be negative, got ${platformShare}%`);
180
+ }
181
+ }
182
+ return await this.revenueShareRuleService_.update({ ...data, id }, sharedContext);
183
+ }
184
+ async deleteRevenueRule(id, sharedContext = {}) {
185
+ return await this.revenueShareRuleService_.delete(id, sharedContext);
186
+ }
187
+ // ===== COMMISSION CALCULATION (Enhanced with Revenue Sharing) =====
188
+ async calculateCommissionWithRevenueSharing(data, sharedContext = {}) {
189
+ // 1. Calculate base commission using existing Dub logic
190
+ const baseResult = await this.calculateCommission({
191
+ program_id: data.program_id,
192
+ ambassador_id: data.beneficiary_id, // Use beneficiary for base calculation
193
+ event_type: data.event_type,
194
+ amount: data.amount,
195
+ quantity: data.quantity,
196
+ }, sharedContext);
197
+ // 2. Get revenue sharing rules with plan bonus
198
+ const revenueEvent = {
199
+ program_id: data.program_id,
200
+ current_source_type: data.current_source_type,
201
+ current_source_id: data.current_source_id,
202
+ original_source_type: data.original_source_type,
203
+ original_source_id: data.original_source_id,
204
+ actor_id: data.actor_id,
205
+ actor_type: data.actor_type,
206
+ context_owner_id: data.context_owner_id,
207
+ context_owner_type: data.context_owner_type,
208
+ creator_id: data.creator_id,
209
+ creator_type: data.creator_type,
210
+ beneficiary_id: data.beneficiary_id,
211
+ beneficiary_type: data.beneficiary_type,
212
+ beneficiary_plan: data.beneficiary_plan,
213
+ action: data.event_type === "sale" ? "amplify" : "create",
214
+ context_type: "community",
215
+ relationship: "contributor",
216
+ };
217
+ const revenueDistribution = await this.revenueRuleResolver_.resolveRevenueRules(revenueEvent, sharedContext);
218
+ // 3. Apply revenue sharing to base commission
219
+ const baseCommission = baseResult.total_commission;
220
+ const actorEarnings = Math.round(baseCommission * (revenueDistribution.actor_share / 100));
221
+ const beneficiaryEarnings = Math.round(baseCommission * (revenueDistribution.beneficiary_share / 100));
222
+ const contextOwnerEarnings = Math.round(baseCommission * (revenueDistribution.context_owner_share / 100));
223
+ const creatorEarnings = Math.round(baseCommission * (revenueDistribution.creator_share / 100));
224
+ const platformEarnings = Math.round(baseCommission * (revenueDistribution.platform_share / 100));
225
+ return {
226
+ base_commission: baseCommission,
227
+ revenue_distribution: revenueDistribution,
228
+ actor_earnings: actorEarnings,
229
+ beneficiary_earnings: beneficiaryEarnings,
230
+ context_owner_earnings: contextOwnerEarnings,
231
+ creator_earnings: creatorEarnings,
232
+ platform_earnings: platformEarnings,
233
+ total_distributed: actorEarnings +
234
+ beneficiaryEarnings +
235
+ contextOwnerEarnings +
236
+ creatorEarnings +
237
+ platformEarnings,
238
+ };
239
+ }
240
+ async calculateCommission(data, sharedContext = {}) {
241
+ // Get enrollment with reward assignments
242
+ const enrollments = await this.listEnrollmentsByProgram(data.program_id, { ambassador_id: data.ambassador_id, status: "approved" }, {}, sharedContext);
243
+ if (!enrollments?.length) {
244
+ return {
245
+ ambassador_earnings: 0,
246
+ total_commission: 0,
247
+ };
248
+ }
249
+ const enrollment = enrollments[0];
250
+ let rewardId;
251
+ // Get reward based on event type (Dub pattern)
252
+ switch (data.event_type) {
253
+ case "click":
254
+ rewardId = enrollment.click_reward_id;
255
+ break;
256
+ case "lead":
257
+ rewardId = enrollment.lead_reward_id;
258
+ break;
259
+ case "sale":
260
+ rewardId = enrollment.sale_reward_id;
261
+ break;
262
+ }
263
+ if (!rewardId) {
264
+ return {
265
+ ambassador_earnings: 0,
266
+ total_commission: 0,
267
+ };
268
+ }
269
+ // Get reward details
270
+ const reward = await this.retrieveReward(rewardId, {}, sharedContext);
271
+ // Calculate base commission (Dub logic)
272
+ let baseCommission = 0;
273
+ if (reward.type === "percentage") {
274
+ baseCommission = Math.round((data.amount || 0) * (reward.amount / 100));
275
+ }
276
+ else if (reward.type === "flat") {
277
+ baseCommission = reward.amount * (data.quantity || 1);
278
+ }
279
+ // Apply our revenue sharing scenarios
280
+ let ambassadorEarnings = baseCommission;
281
+ let creatorEarnings = 0;
282
+ let communityEarnings = 0;
283
+ switch (data.source_type) {
284
+ case "community":
285
+ // 70% ambassador, 30% creator
286
+ ambassadorEarnings = Math.round(baseCommission * 0.7);
287
+ creatorEarnings = Math.round(baseCommission * 0.3);
288
+ break;
289
+ case "repost":
290
+ // Ambassador gets commission
291
+ ambassadorEarnings = baseCommission;
292
+ break;
293
+ default:
294
+ // Direct: 100% to ambassador
295
+ ambassadorEarnings = baseCommission;
296
+ }
297
+ // Apply reward limits
298
+ if (reward.max_amount && ambassadorEarnings > reward.max_amount) {
299
+ ambassadorEarnings = reward.max_amount;
300
+ }
301
+ return {
302
+ ambassador_earnings: ambassadorEarnings,
303
+ creator_earnings: creatorEarnings,
304
+ community_earnings: communityEarnings,
305
+ total_commission: ambassadorEarnings + creatorEarnings + communityEarnings,
306
+ reward_used: reward,
307
+ };
308
+ }
309
+ async getAnalyticsTimeseries(params, sharedContext = {}) {
310
+ const manager = sharedContext.manager;
311
+ const query = `
312
+ SELECT
313
+ TO_CHAR((created_at AT TIME ZONE 'UTC' AT TIME ZONE $1), $2) AS start,
314
+ COUNT(CASE WHEN event_type = 'click' THEN 1 END)::int AS clicks,
315
+ COUNT(CASE WHEN event_type = 'lead' THEN 1 END)::int AS leads,
316
+ COUNT(CASE WHEN event_type = 'sale' THEN 1 END)::int AS sales,
317
+ COALESCE(SUM(CASE WHEN event_type = 'sale' AND earnings > 0 THEN earnings ELSE 0 END), 0)::int AS "saleAmount",
318
+ COALESCE(SUM(CASE WHEN event_type = 'sale' AND earnings > 0 THEN earnings ELSE 0 END), 0)::int AS earnings
319
+ FROM commission
320
+ WHERE
321
+ ambassador_id = $3
322
+ ${params.program_id ? "AND program_id = $4" : ""}
323
+ AND created_at >= $${params.program_id ? "5" : "4"}::timestamp
324
+ AND created_at < $${params.program_id ? "6" : "5"}::timestamp
325
+ AND status IN ('confirmed', 'processed', 'paid')
326
+ GROUP BY start
327
+ ORDER BY start ASC
328
+ `;
329
+ const queryParams = [
330
+ params.timezone,
331
+ params.dateFormat,
332
+ params.ambassador_id,
333
+ ...(params.program_id ? [params.program_id] : []),
334
+ params.start,
335
+ params.end,
336
+ ];
337
+ return (await manager?.execute(query, queryParams)) || [];
338
+ }
339
+ async getAnalytics(params, sharedContext = {}) {
340
+ // Use Dub's date utilities
341
+ const { startDate, endDate, granularity, dateFormat } = (0, analytics_1.getStartEndDates)({
342
+ interval: params.interval,
343
+ start: params.start,
344
+ end: params.end,
345
+ });
346
+ const startStr = startDate.toISOString();
347
+ const endStr = endDate.toISOString();
348
+ const timezone = params.timezone || "UTC";
349
+ // For timeseries, use custom query (Dub pattern)
350
+ if (params.groupBy === "timeseries") {
351
+ const timeseries = await this.getAnalyticsTimeseries({
352
+ ambassador_id: params.ambassador_id,
353
+ program_id: params.program_id,
354
+ granularity,
355
+ dateFormat,
356
+ start: startStr,
357
+ end: endStr,
358
+ timezone,
359
+ }, sharedContext);
360
+ // Calculate totals (Dub pattern)
361
+ const totals = timeseries.reduce((acc, item) => ({
362
+ clicks: acc.clicks + item.clicks,
363
+ leads: acc.leads + item.leads,
364
+ sales: acc.sales + item.sales,
365
+ saleAmount: acc.saleAmount + item.saleAmount,
366
+ }), { clicks: 0, leads: 0, sales: 0, saleAmount: 0 });
367
+ return { ...totals, earnings: totals.saleAmount, timeseries };
368
+ }
369
+ // For count, use aggregate query (Dub pattern)
370
+ const manager = sharedContext.manager;
371
+ const countQuery = `
372
+ SELECT
373
+ COUNT(CASE WHEN event_type = 'click' THEN 1 END)::int AS clicks,
374
+ COUNT(CASE WHEN event_type = 'lead' THEN 1 END)::int AS leads,
375
+ COUNT(CASE WHEN event_type = 'sale' THEN 1 END)::int AS sales,
376
+ COALESCE(SUM(CASE WHEN event_type = 'sale' AND earnings > 0 THEN earnings ELSE 0 END), 0)::int AS "saleAmount"
377
+ FROM commission
378
+ WHERE
379
+ ambassador_id = $1
380
+ ${params.program_id ? "AND program_id = $2" : ""}
381
+ AND created_at >= $${params.program_id ? "3" : "2"}::timestamp
382
+ AND created_at < $${params.program_id ? "4" : "3"}::timestamp
383
+ AND status IN ('confirmed', 'processed', 'paid')
384
+ `;
385
+ const countParams = [
386
+ params.ambassador_id,
387
+ ...(params.program_id ? [params.program_id] : []),
388
+ startStr,
389
+ endStr,
390
+ ];
391
+ const [result] = (await manager?.execute(countQuery, countParams)) || [
392
+ { clicks: 0, leads: 0, sales: 0, saleAmount: 0 },
393
+ ];
394
+ // todo fix
395
+ // @ts-ignore
396
+ return { ...result, earnings: result.saleAmount };
397
+ }
398
+ async findProgramsByResource(params, sharedContext = {}) {
399
+ const manager = sharedContext.manager;
400
+ // Query to determine program access based on ownership and settings
401
+ const query = `
402
+ SELECT
403
+ p.*,
404
+ pe.status as enrollment_status,
405
+ CASE
406
+ WHEN p.auto_approve_ambassadors = true THEN 'public'
407
+ ELSE 'private'
408
+ END as access_type,
409
+ CASE
410
+ WHEN p.owner_id = (
411
+ SELECT owner_id FROM ${params.resource_type}
412
+ WHERE id = $3
413
+ ) THEN true
414
+ ELSE false
415
+ END as is_owner_match,
416
+ CASE
417
+ WHEN pe.status = 'approved' THEN true
418
+ WHEN p.auto_approve_ambassadors = true THEN true
419
+ WHEN p.owner_id = (
420
+ SELECT owner_id FROM ${params.resource_type}
421
+ WHERE id = $3
422
+ ) THEN true
423
+ ELSE false
424
+ END as can_activate
425
+ FROM program p
426
+ LEFT JOIN program_enrollment pe ON (
427
+ pe.program_id = p.id
428
+ AND pe.ambassador_id = $1
429
+ AND pe.status IN ('approved', 'pending')
430
+ )
431
+ WHERE
432
+ p.status = $2
433
+ ${params.category ? "AND p.category = $4" : ""}
434
+ ${params.access_type
435
+ ? `AND (
436
+ CASE
437
+ WHEN p.auto_approve_ambassadors = true THEN 'public'
438
+ ELSE 'private'
439
+ END = $${params.category ? "5" : "4"}
440
+ )`
441
+ : ""}
442
+ ORDER BY p.created_at DESC
443
+ `;
444
+ const queryParams = [
445
+ params.ambassador_id || null,
446
+ params.status || "active",
447
+ params.resource_id,
448
+ ...(params.category ? [params.category] : []),
449
+ ...(params.access_type ? [params.access_type] : []),
450
+ ];
451
+ const results = (await manager?.execute(query, queryParams)) || [];
452
+ // The 'program' field must fulfill the ProgramDTO type.
453
+ // Return all properties defined in ProgramDTO, even if null/undefined if not present in row.
454
+ // @ts-ignore
455
+ return results.map((row) => ({
456
+ program: {
457
+ id: row.id,
458
+ owner_id: row.owner_id,
459
+ owner_type: row.owner_type,
460
+ name: row.name,
461
+ slug: row.slug,
462
+ description: row.description,
463
+ category: row.category,
464
+ commission_type: row.commission_type,
465
+ commission_rate: row.commission_rate,
466
+ commission_currency: row.commission_currency,
467
+ commission_min_payout: row.commission_min_payout,
468
+ commission_summary: row.commission_summary,
469
+ auto_approve_ambassadors: row.auto_approve_ambassadors,
470
+ max_ambassador_links: row.max_ambassador_links,
471
+ is_active: row.is_active,
472
+ status: row.status,
473
+ created_at: row.created_at,
474
+ updated_at: row.updated_at,
475
+ deleted_at: row.deleted_at,
476
+ },
477
+ enrollment_status: row.enrollment_status,
478
+ can_activate: row.can_activate,
479
+ access_type: row.access_type,
480
+ is_owner_match: row.is_owner_match,
481
+ }));
482
+ }
483
+ // ===== ENROLLMENT MANAGEMENT =====
484
+ async createEnrollment(data, sharedContext = {}) {
485
+ return await this.programEnrollmentService_.create({
486
+ program_id: data.program_id,
487
+ ambassador_id: data.ambassador_id,
488
+ application_message: data.application_message,
489
+ status: data.status || "pending",
490
+ source: data.source || "application",
491
+ invited_by: data.invited_by,
492
+ metadata: data.metadata,
493
+ }, sharedContext);
494
+ }
495
+ async updateProgramEnrollment(id, data, sharedContext = {}) {
496
+ return await this.programEnrollmentService_.update({ ...data, id }, sharedContext);
497
+ }
498
+ async retrieveEnrollment(id, sharedContext = {}) {
499
+ return await this.programEnrollmentService_.retrieve(id, {}, sharedContext);
500
+ }
501
+ async updateEnrollment(id, data, sharedContext = {}) {
502
+ data.id = id;
503
+ return await this.programEnrollmentService_.update(data, sharedContext);
504
+ }
505
+ async deleteEnrollments(ids, sharedContext = {}) {
506
+ await this.programEnrollmentService_.delete(ids, sharedContext);
507
+ }
508
+ // ===== WORKFLOW-LEVEL OPERATIONS (Cross-Module Dependencies) =====
509
+ // These operations require workflow orchestration due to external module dependencies:
510
+ // 🔄 createAmbassadorWithLink() → Needs Link Module (create-partner-link.ts)
511
+ // 🔄 createAndEnrollAmbassador() → Needs Link + Group Modules (create-and-enroll-partner.ts)
512
+ // 🔄 notifyCommissionCreated() → Needs Email/Notification Module (notify-partner-commission.ts)
513
+ // 🔄 backfillCommissions() → Needs Analytics/Tinybird Module (backfill-link-commissions.ts)
514
+ // 🔄 bulkDeleteAmbassadors() → Needs Link Module cleanup (bulk-delete-partners.ts)
515
+ // ===== COMMISSION METHODS (Atomic Operations for API) =====
516
+ async createCommission(data, sharedContext = {}) {
517
+ return await this.commissionService_.createCommission(data, sharedContext);
518
+ }
519
+ /**
520
+ * Updates an array of commissions by ID with provided fields.
521
+ *
522
+ * @param ids string[] - list of commission IDs
523
+ * @param data Partial<CommissionDTO> - fields to update for all IDs
524
+ * @returns Promise<CommissionDTO[]>
525
+ *
526
+ * Example: updateCommissions(["comm_123", "comm_456"], { payout_id: "payout_123" })
527
+ */
528
+ // @ts-expect-error
529
+ async updateCommissions(ids, data, sharedContext = {}) {
530
+ // Transform ids into the expected bulk update shape for service
531
+ const payload = ids.map(id => ({
532
+ ...data,
533
+ id,
534
+ }));
535
+ return await this.commissionService_.update(payload, sharedContext);
536
+ }
537
+ // @ts-expect-error
538
+ async createCommissions(data, sharedContext = {}) {
539
+ return await this.commissionService_.create(data, sharedContext);
540
+ }
541
+ // @ts-expect-error
542
+ async listCommissions(filters = {}, config = {}, sharedContext = {}) {
543
+ return await this.commissionService_.getCommissionsByFilters(filters, config, sharedContext);
544
+ }
545
+ async updateCommissionStatus(commissionId, status, sharedContext = {}) {
546
+ return await this.commissionService_.updateCommissionStatus(commissionId, status, sharedContext);
547
+ }
548
+ // ===== PERFORMANCE ANALYTICS (Module-Level Composition) =====
549
+ async getAmbassadorPerformance(ambassadorId, filters = {}, sharedContext = {}) {
550
+ const commissions = await this.commissionService_.getCommissionsByFilters({
551
+ ambassador_id: ambassadorId,
552
+ ...filters,
553
+ }, {}, sharedContext);
554
+ const totalEarnings = commissions.reduce((sum, c) => sum + c.earnings, 0);
555
+ const clickCount = commissions.filter((c) => c.type === "click").length;
556
+ const saleCount = commissions.filter((c) => c.type === "sale").length;
557
+ const conversionRate = clickCount > 0 ? (saleCount / clickCount) * 100 : 0;
558
+ return {
559
+ total_commissions: commissions.length,
560
+ total_earnings: totalEarnings,
561
+ click_count: clickCount,
562
+ sale_count: saleCount,
563
+ conversion_rate: Math.round(conversionRate * 100) / 100,
564
+ };
565
+ }
566
+ async getPayoutEligibleCommissions(programId, ambassadorId, sharedContext = {}) {
567
+ // Get program to determine holding period
568
+ const program = await this.programService_.getProgramOrThrow(programId, undefined, undefined, sharedContext);
569
+ // Calculate cutoff date
570
+ const cutoffDate = program.holding_period_days > 0
571
+ ? new Date(Date.now() - program.holding_period_days * 24 * 60 * 60 * 1000)
572
+ : new Date(0);
573
+ // Get eligible commissions and clawbacks
574
+ const { eligible, clawbacks } = await this.commissionService_.getCommissionsForPayout(programId, ambassadorId, cutoffDate, sharedContext);
575
+ return {
576
+ eligible,
577
+ clawbacks,
578
+ holdingPeriodDays: program.holding_period_days,
579
+ };
580
+ }
581
+ // ===== REWARD METHODS (Atomic Operations for API) =====
582
+ // @ts-expect-error
583
+ async createReward(data, sharedContext = {}) {
584
+ return await this.rewardService_.createReward(data, sharedContext);
585
+ }
586
+ async listRewardsByProgram(programId, filters = {}, config = {}, sharedContext = {}) {
587
+ return await this.rewardService_.getRewardsByProgram(programId, filters, config, sharedContext);
588
+ }
589
+ // ===== PAYOUT METHODS (Atomic Operations for API) =====
590
+ async createPayout(data, sharedContext = {}) {
591
+ return await this.payoutService_.createPayout(data, sharedContext);
592
+ }
593
+ async listPayoutsByProgram(programId, filters = {}, config = {}, sharedContext = {}) {
594
+ return await this.payoutService_.getPayoutsByProgram(programId, filters, config, sharedContext);
595
+ }
596
+ async getEligiblePayouts(programId, cutoffDate, sharedContext = {}) {
597
+ // Get program to determine min payout amount
598
+ const program = await this.programService_.getProgramOrThrow(programId, undefined, undefined, sharedContext);
599
+ return await this.payoutService_.getEligiblePayouts(programId, program.min_payout_amount, cutoffDate, sharedContext);
600
+ }
601
+ async updatePayoutStatus(payoutId, status, sharedContext = {}) {
602
+ return await this.payoutService_.updatePayoutStatus(payoutId, status, sharedContext);
603
+ }
604
+ // ===== COMMISSION TRACKING =====
605
+ async recordCommission(data, sharedContext = {}) {
606
+ // TODO: Calculate earnings based on reward rules
607
+ const commission = await this.commissionService_.create([
608
+ {
609
+ id: (0, utils_1.generateEntityId)("", "com"),
610
+ ...data,
611
+ earnings: data.earnings || 0,
612
+ currency: "usd",
613
+ status: "pending",
614
+ },
615
+ ], sharedContext);
616
+ return commission[0];
617
+ }
618
+ }
619
+ exports.default = AmbassadorModuleService;
620
+ __decorate([
621
+ (0, utils_1.InjectTransactionManager)(),
622
+ __param(3, (0, utils_1.EtoContext)()),
623
+ __metadata("design:type", Function),
624
+ __metadata("design:paramtypes", [String, String, Object, Object]),
625
+ __metadata("design:returntype", Promise)
626
+ ], AmbassadorModuleService.prototype, "createAmbassador", null);
627
+ __decorate([
628
+ (0, utils_1.InjectManager)(),
629
+ __param(2, (0, utils_1.EtoContext)()),
630
+ __metadata("design:type", Function),
631
+ __metadata("design:paramtypes", [String, String, Object]),
632
+ __metadata("design:returntype", Promise)
633
+ ], AmbassadorModuleService.prototype, "getAmbassadorBySource", null);
634
+ __decorate([
635
+ (0, utils_1.InjectManager)()
636
+ // @ts-expect-error
637
+ ,
638
+ __param(2, (0, utils_1.EtoContext)()),
639
+ __metadata("design:type", Function),
640
+ __metadata("design:paramtypes", [Object, Object, Object]),
641
+ __metadata("design:returntype", Promise)
642
+ ], AmbassadorModuleService.prototype, "listAmbassadors", null);
643
+ __decorate([
644
+ (0, utils_1.InjectTransactionManager)(),
645
+ __param(2, (0, utils_1.EtoContext)()),
646
+ __metadata("design:type", Function),
647
+ __metadata("design:paramtypes", [String, String, Object]),
648
+ __metadata("design:returntype", Promise)
649
+ ], AmbassadorModuleService.prototype, "verifyWebsite", null);
650
+ __decorate([
651
+ (0, utils_1.InjectTransactionManager)(),
652
+ __param(2, (0, utils_1.EtoContext)()),
653
+ __metadata("design:type", Function),
654
+ __metadata("design:paramtypes", [String, String, Object]),
655
+ __metadata("design:returntype", Promise)
656
+ ], AmbassadorModuleService.prototype, "verifyYoutube", null);
657
+ __decorate([
658
+ (0, utils_1.InjectTransactionManager)(),
659
+ __param(1, (0, utils_1.EtoContext)()),
660
+ __metadata("design:type", Function),
661
+ __metadata("design:paramtypes", [Object, Object]),
662
+ __metadata("design:returntype", Promise)
663
+ ], AmbassadorModuleService.prototype, "createProgram", null);
664
+ __decorate([
665
+ (0, utils_1.InjectManager)(),
666
+ __param(3, (0, utils_1.EtoContext)()),
667
+ __metadata("design:type", Function),
668
+ __metadata("design:paramtypes", [String, String, String, Object]),
669
+ __metadata("design:returntype", Promise)
670
+ ], AmbassadorModuleService.prototype, "getProgramOrThrow", null);
671
+ __decorate([
672
+ (0, utils_1.InjectManager)(),
673
+ __param(4, (0, utils_1.EtoContext)()),
674
+ __metadata("design:type", Function),
675
+ __metadata("design:paramtypes", [String, String, Object, Object, Object]),
676
+ __metadata("design:returntype", Promise)
677
+ ], AmbassadorModuleService.prototype, "listProgramsByOwner", null);
678
+ __decorate([
679
+ (0, utils_1.InjectTransactionManager)(),
680
+ __param(1, (0, utils_1.EtoContext)()),
681
+ __metadata("design:type", Function),
682
+ __metadata("design:paramtypes", [Object, Object]),
683
+ __metadata("design:returntype", Promise)
684
+ ], AmbassadorModuleService.prototype, "updateProgram", null);
685
+ __decorate([
686
+ (0, utils_1.InjectTransactionManager)(),
687
+ __param(1, (0, utils_1.EtoContext)()),
688
+ __metadata("design:type", Function),
689
+ __metadata("design:paramtypes", [Object, Object]),
690
+ __metadata("design:returntype", Promise)
691
+ ], AmbassadorModuleService.prototype, "enrollAmbassador", null);
692
+ __decorate([
693
+ (0, utils_1.InjectTransactionManager)(),
694
+ __param(1, (0, utils_1.EtoContext)()),
695
+ __metadata("design:type", Function),
696
+ __metadata("design:paramtypes", [String, Object]),
697
+ __metadata("design:returntype", Promise)
698
+ ], AmbassadorModuleService.prototype, "approveEnrollment", null);
699
+ __decorate([
700
+ (0, utils_1.InjectManager)(),
701
+ __param(2, (0, utils_1.EtoContext)()),
702
+ __metadata("design:type", Function),
703
+ __metadata("design:paramtypes", [String, String, Object]),
704
+ __metadata("design:returntype", Promise)
705
+ ], AmbassadorModuleService.prototype, "getEnrollmentOrThrow", null);
706
+ __decorate([
707
+ (0, utils_1.InjectManager)(),
708
+ __param(3, (0, utils_1.EtoContext)()),
709
+ __metadata("design:type", Function),
710
+ __metadata("design:paramtypes", [String, Object, Object, Object]),
711
+ __metadata("design:returntype", Promise)
712
+ ], AmbassadorModuleService.prototype, "listEnrollmentsByProgram", null);
713
+ __decorate([
714
+ (0, utils_1.InjectManager)(),
715
+ __param(3, (0, utils_1.EtoContext)()),
716
+ __metadata("design:type", Function),
717
+ __metadata("design:paramtypes", [String, String, Number, Object]),
718
+ __metadata("design:returntype", Promise)
719
+ ], AmbassadorModuleService.prototype, "calculateEarnings", null);
720
+ __decorate([
721
+ (0, utils_1.InjectTransactionManager)()
722
+ // @ts-expect-error
723
+ ,
724
+ __param(1, (0, utils_1.EtoContext)()),
725
+ __metadata("design:type", Function),
726
+ __metadata("design:paramtypes", [Object, Object]),
727
+ __metadata("design:returntype", Promise)
728
+ ], AmbassadorModuleService.prototype, "createReward", null);
729
+ __decorate([
730
+ (0, utils_1.InjectManager)()
731
+ // @ts-expect-error
732
+ ,
733
+ __param(2, (0, utils_1.EtoContext)()),
734
+ __metadata("design:type", Function),
735
+ __metadata("design:paramtypes", [Object, Object, Object]),
736
+ __metadata("design:returntype", Promise)
737
+ ], AmbassadorModuleService.prototype, "listRewards", null);
738
+ __decorate([
739
+ (0, utils_1.InjectManager)()
740
+ // @ts-expect-error
741
+ ,
742
+ __param(2, (0, utils_1.EtoContext)()),
743
+ __metadata("design:type", Function),
744
+ __metadata("design:paramtypes", [String, Object, Object]),
745
+ __metadata("design:returntype", Promise)
746
+ ], AmbassadorModuleService.prototype, "retrieveReward", null);
747
+ __decorate([
748
+ (0, utils_1.InjectTransactionManager)(),
749
+ __param(2, (0, utils_1.EtoContext)()),
750
+ __metadata("design:type", Function),
751
+ __metadata("design:paramtypes", [String, Object, Object]),
752
+ __metadata("design:returntype", Promise)
753
+ ], AmbassadorModuleService.prototype, "updateReward", null);
754
+ __decorate([
755
+ (0, utils_1.InjectTransactionManager)(),
756
+ __param(1, (0, utils_1.EtoContext)()),
757
+ __metadata("design:type", Function),
758
+ __metadata("design:paramtypes", [String, Object]),
759
+ __metadata("design:returntype", Promise)
760
+ ], AmbassadorModuleService.prototype, "deleteReward", null);
761
+ __decorate([
762
+ (0, utils_1.InjectTransactionManager)(),
763
+ __param(1, (0, utils_1.EtoContext)()),
764
+ __metadata("design:type", Function),
765
+ __metadata("design:paramtypes", [Object, Object]),
766
+ __metadata("design:returntype", Promise)
767
+ ], AmbassadorModuleService.prototype, "createRevenueRule", null);
768
+ __decorate([
769
+ (0, utils_1.InjectManager)(),
770
+ __param(2, (0, utils_1.EtoContext)()),
771
+ __metadata("design:type", Function),
772
+ __metadata("design:paramtypes", [Object, Object, Object]),
773
+ __metadata("design:returntype", Promise)
774
+ ], AmbassadorModuleService.prototype, "listRevenueRules", null);
775
+ __decorate([
776
+ (0, utils_1.InjectManager)(),
777
+ __param(2, (0, utils_1.EtoContext)()),
778
+ __metadata("design:type", Function),
779
+ __metadata("design:paramtypes", [String, Object, Object]),
780
+ __metadata("design:returntype", Promise)
781
+ ], AmbassadorModuleService.prototype, "retrieveRevenueRule", null);
782
+ __decorate([
783
+ (0, utils_1.InjectTransactionManager)(),
784
+ __param(2, (0, utils_1.EtoContext)()),
785
+ __metadata("design:type", Function),
786
+ __metadata("design:paramtypes", [String, Object, Object]),
787
+ __metadata("design:returntype", Promise)
788
+ ], AmbassadorModuleService.prototype, "updateRevenueRule", null);
789
+ __decorate([
790
+ (0, utils_1.InjectTransactionManager)(),
791
+ __param(1, (0, utils_1.EtoContext)()),
792
+ __metadata("design:type", Function),
793
+ __metadata("design:paramtypes", [String, Object]),
794
+ __metadata("design:returntype", Promise)
795
+ ], AmbassadorModuleService.prototype, "deleteRevenueRule", null);
796
+ __decorate([
797
+ (0, utils_1.InjectManager)(),
798
+ __param(1, (0, utils_1.EtoContext)()),
799
+ __metadata("design:type", Function),
800
+ __metadata("design:paramtypes", [Object, Object]),
801
+ __metadata("design:returntype", Promise)
802
+ ], AmbassadorModuleService.prototype, "calculateCommissionWithRevenueSharing", null);
803
+ __decorate([
804
+ (0, utils_1.InjectManager)(),
805
+ __param(1, (0, utils_1.EtoContext)()),
806
+ __metadata("design:type", Function),
807
+ __metadata("design:paramtypes", [Object, Object]),
808
+ __metadata("design:returntype", Promise)
809
+ ], AmbassadorModuleService.prototype, "calculateCommission", null);
810
+ __decorate([
811
+ (0, utils_1.InjectManager)("AmbassadorRepository_"),
812
+ __param(1, (0, utils_1.EtoContext)()),
813
+ __metadata("design:type", Function),
814
+ __metadata("design:paramtypes", [Object, Object]),
815
+ __metadata("design:returntype", Promise)
816
+ ], AmbassadorModuleService.prototype, "getAnalyticsTimeseries", null);
817
+ __decorate([
818
+ (0, utils_1.InjectManager)(),
819
+ __param(1, (0, utils_1.EtoContext)()),
820
+ __metadata("design:type", Function),
821
+ __metadata("design:paramtypes", [Object, Object]),
822
+ __metadata("design:returntype", Promise)
823
+ ], AmbassadorModuleService.prototype, "getAnalytics", null);
824
+ __decorate([
825
+ (0, utils_1.InjectManager)(),
826
+ __param(1, (0, utils_1.EtoContext)()),
827
+ __metadata("design:type", Function),
828
+ __metadata("design:paramtypes", [Object, Object]),
829
+ __metadata("design:returntype", Promise)
830
+ ], AmbassadorModuleService.prototype, "findProgramsByResource", null);
831
+ __decorate([
832
+ (0, utils_1.InjectManager)(),
833
+ __param(1, (0, utils_1.EtoContext)()),
834
+ __metadata("design:type", Function),
835
+ __metadata("design:paramtypes", [Object, Object]),
836
+ __metadata("design:returntype", Promise)
837
+ ], AmbassadorModuleService.prototype, "createEnrollment", null);
838
+ __decorate([
839
+ (0, utils_1.InjectManager)(),
840
+ __param(2, (0, utils_1.EtoContext)()),
841
+ __metadata("design:type", Function),
842
+ __metadata("design:paramtypes", [String, Object, Object]),
843
+ __metadata("design:returntype", Promise)
844
+ ], AmbassadorModuleService.prototype, "updateProgramEnrollment", null);
845
+ __decorate([
846
+ (0, utils_1.InjectManager)(),
847
+ __param(1, (0, utils_1.EtoContext)()),
848
+ __metadata("design:type", Function),
849
+ __metadata("design:paramtypes", [String, Object]),
850
+ __metadata("design:returntype", Promise)
851
+ ], AmbassadorModuleService.prototype, "retrieveEnrollment", null);
852
+ __decorate([
853
+ (0, utils_1.InjectManager)(),
854
+ __param(2, (0, utils_1.EtoContext)()),
855
+ __metadata("design:type", Function),
856
+ __metadata("design:paramtypes", [String, Object, Object]),
857
+ __metadata("design:returntype", Promise)
858
+ ], AmbassadorModuleService.prototype, "updateEnrollment", null);
859
+ __decorate([
860
+ (0, utils_1.InjectManager)(),
861
+ __param(1, (0, utils_1.EtoContext)()),
862
+ __metadata("design:type", Function),
863
+ __metadata("design:paramtypes", [Array, Object]),
864
+ __metadata("design:returntype", Promise)
865
+ ], AmbassadorModuleService.prototype, "deleteEnrollments", null);
866
+ __decorate([
867
+ (0, utils_1.InjectTransactionManager)(),
868
+ __param(1, (0, utils_1.EtoContext)()),
869
+ __metadata("design:type", Function),
870
+ __metadata("design:paramtypes", [Object, Object]),
871
+ __metadata("design:returntype", Promise)
872
+ ], AmbassadorModuleService.prototype, "createCommission", null);
873
+ __decorate([
874
+ (0, utils_1.InjectTransactionManager)()
875
+ // @ts-expect-error
876
+ ,
877
+ __param(2, (0, utils_1.EtoContext)()),
878
+ __metadata("design:type", Function),
879
+ __metadata("design:paramtypes", [Array, Object, Object]),
880
+ __metadata("design:returntype", Promise)
881
+ ], AmbassadorModuleService.prototype, "updateCommissions", null);
882
+ __decorate([
883
+ (0, utils_1.InjectTransactionManager)()
884
+ // @ts-expect-error
885
+ ,
886
+ __param(1, (0, utils_1.EtoContext)()),
887
+ __metadata("design:type", Function),
888
+ __metadata("design:paramtypes", [Array, Object]),
889
+ __metadata("design:returntype", Promise)
890
+ ], AmbassadorModuleService.prototype, "createCommissions", null);
891
+ __decorate([
892
+ (0, utils_1.InjectManager)()
893
+ // @ts-expect-error
894
+ ,
895
+ __param(2, (0, utils_1.EtoContext)()),
896
+ __metadata("design:type", Function),
897
+ __metadata("design:paramtypes", [Object, Object, Object]),
898
+ __metadata("design:returntype", Promise)
899
+ ], AmbassadorModuleService.prototype, "listCommissions", null);
900
+ __decorate([
901
+ (0, utils_1.InjectTransactionManager)(),
902
+ __param(2, (0, utils_1.EtoContext)()),
903
+ __metadata("design:type", Function),
904
+ __metadata("design:paramtypes", [String, String, Object]),
905
+ __metadata("design:returntype", Promise)
906
+ ], AmbassadorModuleService.prototype, "updateCommissionStatus", null);
907
+ __decorate([
908
+ (0, utils_1.InjectManager)(),
909
+ __param(2, (0, utils_1.EtoContext)()),
910
+ __metadata("design:type", Function),
911
+ __metadata("design:paramtypes", [String, Object, Object]),
912
+ __metadata("design:returntype", Promise)
913
+ ], AmbassadorModuleService.prototype, "getAmbassadorPerformance", null);
914
+ __decorate([
915
+ (0, utils_1.InjectManager)(),
916
+ __param(2, (0, utils_1.EtoContext)()),
917
+ __metadata("design:type", Function),
918
+ __metadata("design:paramtypes", [String, String, Object]),
919
+ __metadata("design:returntype", Promise)
920
+ ], AmbassadorModuleService.prototype, "getPayoutEligibleCommissions", null);
921
+ __decorate([
922
+ (0, utils_1.InjectTransactionManager)()
923
+ // @ts-expect-error
924
+ ,
925
+ __param(1, (0, utils_1.EtoContext)()),
926
+ __metadata("design:type", Function),
927
+ __metadata("design:paramtypes", [Object, Object]),
928
+ __metadata("design:returntype", Promise)
929
+ ], AmbassadorModuleService.prototype, "createReward", null);
930
+ __decorate([
931
+ (0, utils_1.InjectManager)(),
932
+ __param(3, (0, utils_1.EtoContext)()),
933
+ __metadata("design:type", Function),
934
+ __metadata("design:paramtypes", [String, Object, Object, Object]),
935
+ __metadata("design:returntype", Promise)
936
+ ], AmbassadorModuleService.prototype, "listRewardsByProgram", null);
937
+ __decorate([
938
+ (0, utils_1.InjectTransactionManager)(),
939
+ __param(1, (0, utils_1.EtoContext)()),
940
+ __metadata("design:type", Function),
941
+ __metadata("design:paramtypes", [Object, Object]),
942
+ __metadata("design:returntype", Promise)
943
+ ], AmbassadorModuleService.prototype, "createPayout", null);
944
+ __decorate([
945
+ (0, utils_1.InjectManager)(),
946
+ __param(3, (0, utils_1.EtoContext)()),
947
+ __metadata("design:type", Function),
948
+ __metadata("design:paramtypes", [String, Object, Object, Object]),
949
+ __metadata("design:returntype", Promise)
950
+ ], AmbassadorModuleService.prototype, "listPayoutsByProgram", null);
951
+ __decorate([
952
+ (0, utils_1.InjectManager)(),
953
+ __param(2, (0, utils_1.EtoContext)()),
954
+ __metadata("design:type", Function),
955
+ __metadata("design:paramtypes", [String, Date, Object]),
956
+ __metadata("design:returntype", Promise)
957
+ ], AmbassadorModuleService.prototype, "getEligiblePayouts", null);
958
+ __decorate([
959
+ (0, utils_1.InjectTransactionManager)(),
960
+ __param(2, (0, utils_1.EtoContext)()),
961
+ __metadata("design:type", Function),
962
+ __metadata("design:paramtypes", [String, String, Object]),
963
+ __metadata("design:returntype", Promise)
964
+ ], AmbassadorModuleService.prototype, "updatePayoutStatus", null);
965
+ __decorate([
966
+ (0, utils_1.InjectTransactionManager)(),
967
+ __param(1, (0, utils_1.EtoContext)()),
968
+ __metadata("design:type", Function),
969
+ __metadata("design:paramtypes", [Object, Object]),
970
+ __metadata("design:returntype", Promise)
971
+ ], AmbassadorModuleService.prototype, "recordCommission", null);
972
+ //# sourceMappingURL=ambassador-module-service.js.map