@happyvertical/smrt-sales 0.39.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/AGENTS.md +87 -0
  2. package/CLAUDE.md +1 -0
  3. package/LICENSE +7 -0
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/__smrt-register__.d.ts +2 -0
  6. package/dist/__smrt-register__.d.ts.map +1 -0
  7. package/dist/chunks/__smrt-register__-kWdT7LOt.js +6 -0
  8. package/dist/chunks/__smrt-register__-kWdT7LOt.js.map +1 -0
  9. package/dist/chunks/commissions-BCxqOKVM.js +2181 -0
  10. package/dist/chunks/commissions-BCxqOKVM.js.map +1 -0
  11. package/dist/chunks/crm-DwEz7E2r.js +1428 -0
  12. package/dist/chunks/crm-DwEz7E2r.js.map +1 -0
  13. package/dist/chunks/referrals-BY47p70T.js +2880 -0
  14. package/dist/chunks/referrals-BY47p70T.js.map +1 -0
  15. package/dist/commissions/collections/CommissionAdjustmentCollection.d.ts +26 -0
  16. package/dist/commissions/collections/CommissionAdjustmentCollection.d.ts.map +1 -0
  17. package/dist/commissions/collections/CommissionCollection.d.ts +43 -0
  18. package/dist/commissions/collections/CommissionCollection.d.ts.map +1 -0
  19. package/dist/commissions/collections/CommissionPayoutCollection.d.ts +19 -0
  20. package/dist/commissions/collections/CommissionPayoutCollection.d.ts.map +1 -0
  21. package/dist/commissions/collections/CommissionPlanCollection.d.ts +46 -0
  22. package/dist/commissions/collections/CommissionPlanCollection.d.ts.map +1 -0
  23. package/dist/commissions/collections/EarnerCollection.d.ts +14 -0
  24. package/dist/commissions/collections/EarnerCollection.d.ts.map +1 -0
  25. package/dist/commissions/collections/EarningEventCollection.d.ts +27 -0
  26. package/dist/commissions/collections/EarningEventCollection.d.ts.map +1 -0
  27. package/dist/commissions/collections/index.d.ts +11 -0
  28. package/dist/commissions/collections/index.d.ts.map +1 -0
  29. package/dist/commissions/index.d.ts +20 -0
  30. package/dist/commissions/index.d.ts.map +1 -0
  31. package/dist/commissions/models/Commission.d.ts +150 -0
  32. package/dist/commissions/models/Commission.d.ts.map +1 -0
  33. package/dist/commissions/models/CommissionAdjustment.d.ts +62 -0
  34. package/dist/commissions/models/CommissionAdjustment.d.ts.map +1 -0
  35. package/dist/commissions/models/CommissionPayout.d.ts +119 -0
  36. package/dist/commissions/models/CommissionPayout.d.ts.map +1 -0
  37. package/dist/commissions/models/CommissionPlan.d.ts +117 -0
  38. package/dist/commissions/models/CommissionPlan.d.ts.map +1 -0
  39. package/dist/commissions/models/Earner.d.ts +49 -0
  40. package/dist/commissions/models/Earner.d.ts.map +1 -0
  41. package/dist/commissions/models/EarningEvent.d.ts +89 -0
  42. package/dist/commissions/models/EarningEvent.d.ts.map +1 -0
  43. package/dist/commissions/models/index.d.ts +11 -0
  44. package/dist/commissions/models/index.d.ts.map +1 -0
  45. package/dist/commissions/money.d.ts +42 -0
  46. package/dist/commissions/money.d.ts.map +1 -0
  47. package/dist/commissions/services/CommissionBalanceService.d.ts +14 -0
  48. package/dist/commissions/services/CommissionBalanceService.d.ts.map +1 -0
  49. package/dist/commissions/services/CommissionCalculationService.d.ts +142 -0
  50. package/dist/commissions/services/CommissionCalculationService.d.ts.map +1 -0
  51. package/dist/commissions/services/CommissionPayoutService.d.ts +134 -0
  52. package/dist/commissions/services/CommissionPayoutService.d.ts.map +1 -0
  53. package/dist/commissions/services/CommissionSettlementService.d.ts +42 -0
  54. package/dist/commissions/services/CommissionSettlementService.d.ts.map +1 -0
  55. package/dist/commissions/services/index.d.ts +9 -0
  56. package/dist/commissions/services/index.d.ts.map +1 -0
  57. package/dist/commissions/types.d.ts +243 -0
  58. package/dist/commissions/types.d.ts.map +1 -0
  59. package/dist/commissions.d.ts +2 -0
  60. package/dist/commissions.d.ts.map +1 -0
  61. package/dist/commissions.js +3 -0
  62. package/dist/crm/collections/LeadCollection.d.ts +79 -0
  63. package/dist/crm/collections/LeadCollection.d.ts.map +1 -0
  64. package/dist/crm/collections/OpportunityCollection.d.ts +42 -0
  65. package/dist/crm/collections/OpportunityCollection.d.ts.map +1 -0
  66. package/dist/crm/collections/OpportunityConversionCollection.d.ts +26 -0
  67. package/dist/crm/collections/OpportunityConversionCollection.d.ts.map +1 -0
  68. package/dist/crm/collections/PipelineDefinitionCollection.d.ts +46 -0
  69. package/dist/crm/collections/PipelineDefinitionCollection.d.ts.map +1 -0
  70. package/dist/crm/collections/PipelineStageCollection.d.ts +22 -0
  71. package/dist/crm/collections/PipelineStageCollection.d.ts.map +1 -0
  72. package/dist/crm/collections/SalesActivityCollection.d.ts +24 -0
  73. package/dist/crm/collections/SalesActivityCollection.d.ts.map +1 -0
  74. package/dist/crm/collections/SalesRepresentativeCollection.d.ts +19 -0
  75. package/dist/crm/collections/SalesRepresentativeCollection.d.ts.map +1 -0
  76. package/dist/crm/index.d.ts +27 -0
  77. package/dist/crm/index.d.ts.map +1 -0
  78. package/dist/crm/models/Lead.d.ts +135 -0
  79. package/dist/crm/models/Lead.d.ts.map +1 -0
  80. package/dist/crm/models/Opportunity.d.ts +111 -0
  81. package/dist/crm/models/Opportunity.d.ts.map +1 -0
  82. package/dist/crm/models/OpportunityConversion.d.ts +66 -0
  83. package/dist/crm/models/OpportunityConversion.d.ts.map +1 -0
  84. package/dist/crm/models/PipelineDefinition.d.ts +58 -0
  85. package/dist/crm/models/PipelineDefinition.d.ts.map +1 -0
  86. package/dist/crm/models/PipelineStage.d.ts +66 -0
  87. package/dist/crm/models/PipelineStage.d.ts.map +1 -0
  88. package/dist/crm/models/SalesActivity.d.ts +76 -0
  89. package/dist/crm/models/SalesActivity.d.ts.map +1 -0
  90. package/dist/crm/models/SalesRepresentative.d.ts +60 -0
  91. package/dist/crm/models/SalesRepresentative.d.ts.map +1 -0
  92. package/dist/crm/types.d.ts +228 -0
  93. package/dist/crm/types.d.ts.map +1 -0
  94. package/dist/crm.d.ts +2 -0
  95. package/dist/crm.d.ts.map +1 -0
  96. package/dist/crm.js +3 -0
  97. package/dist/index.d.ts +4 -0
  98. package/dist/index.d.ts.map +1 -0
  99. package/dist/index.js +5 -0
  100. package/dist/manifest.json +9340 -0
  101. package/dist/referrals/collections/AttributionExceptionCollection.d.ts +17 -0
  102. package/dist/referrals/collections/AttributionExceptionCollection.d.ts.map +1 -0
  103. package/dist/referrals/collections/AttributionPolicyCollection.d.ts +50 -0
  104. package/dist/referrals/collections/AttributionPolicyCollection.d.ts.map +1 -0
  105. package/dist/referrals/collections/ReferralAgreementCollection.d.ts +48 -0
  106. package/dist/referrals/collections/ReferralAgreementCollection.d.ts.map +1 -0
  107. package/dist/referrals/collections/ReferralCollection.d.ts +25 -0
  108. package/dist/referrals/collections/ReferralCollection.d.ts.map +1 -0
  109. package/dist/referrals/collections/ReferralLinkCollection.d.ts +96 -0
  110. package/dist/referrals/collections/ReferralLinkCollection.d.ts.map +1 -0
  111. package/dist/referrals/collections/ReferralProgramCollection.d.ts +18 -0
  112. package/dist/referrals/collections/ReferralProgramCollection.d.ts.map +1 -0
  113. package/dist/referrals/collections/ReferralTermSnapshotCollection.d.ts +13 -0
  114. package/dist/referrals/collections/ReferralTermSnapshotCollection.d.ts.map +1 -0
  115. package/dist/referrals/collections/ReferralTouchCollection.d.ts +30 -0
  116. package/dist/referrals/collections/ReferralTouchCollection.d.ts.map +1 -0
  117. package/dist/referrals/collections/ReferrerCollection.d.ts +17 -0
  118. package/dist/referrals/collections/ReferrerCollection.d.ts.map +1 -0
  119. package/dist/referrals/index.d.ts +38 -0
  120. package/dist/referrals/index.d.ts.map +1 -0
  121. package/dist/referrals/models/AttributionException.d.ts +85 -0
  122. package/dist/referrals/models/AttributionException.d.ts.map +1 -0
  123. package/dist/referrals/models/AttributionPolicy.d.ts +128 -0
  124. package/dist/referrals/models/AttributionPolicy.d.ts.map +1 -0
  125. package/dist/referrals/models/Referral.d.ts +112 -0
  126. package/dist/referrals/models/Referral.d.ts.map +1 -0
  127. package/dist/referrals/models/ReferralAgreement.d.ts +125 -0
  128. package/dist/referrals/models/ReferralAgreement.d.ts.map +1 -0
  129. package/dist/referrals/models/ReferralLink.d.ts +71 -0
  130. package/dist/referrals/models/ReferralLink.d.ts.map +1 -0
  131. package/dist/referrals/models/ReferralProgram.d.ts +57 -0
  132. package/dist/referrals/models/ReferralProgram.d.ts.map +1 -0
  133. package/dist/referrals/models/ReferralTermSnapshot.d.ts +61 -0
  134. package/dist/referrals/models/ReferralTermSnapshot.d.ts.map +1 -0
  135. package/dist/referrals/models/ReferralTouch.d.ts +55 -0
  136. package/dist/referrals/models/ReferralTouch.d.ts.map +1 -0
  137. package/dist/referrals/models/Referrer.d.ts +69 -0
  138. package/dist/referrals/models/Referrer.d.ts.map +1 -0
  139. package/dist/referrals/services/AttributionService.d.ts +248 -0
  140. package/dist/referrals/services/AttributionService.d.ts.map +1 -0
  141. package/dist/referrals/services/ReferralCommissionService.d.ts +91 -0
  142. package/dist/referrals/services/ReferralCommissionService.d.ts.map +1 -0
  143. package/dist/referrals/services/ReferralQualificationService.d.ts +135 -0
  144. package/dist/referrals/services/ReferralQualificationService.d.ts.map +1 -0
  145. package/dist/referrals/types.d.ts +226 -0
  146. package/dist/referrals/types.d.ts.map +1 -0
  147. package/dist/referrals.d.ts +2 -0
  148. package/dist/referrals.d.ts.map +1 -0
  149. package/dist/referrals.js +3 -0
  150. package/dist/smrt-knowledge.json +5501 -0
  151. package/dist/svelte/__tests__/format.test.js +68 -0
  152. package/dist/svelte/__tests__/types.test.js +349 -0
  153. package/dist/svelte/components/AttributionConflictQueue.svelte +361 -0
  154. package/dist/svelte/components/AttributionConflictQueue.svelte.d.ts +15 -0
  155. package/dist/svelte/components/AttributionConflictQueue.svelte.d.ts.map +1 -0
  156. package/dist/svelte/components/CommissionBreakdown.svelte +251 -0
  157. package/dist/svelte/components/CommissionBreakdown.svelte.d.ts +11 -0
  158. package/dist/svelte/components/CommissionBreakdown.svelte.d.ts.map +1 -0
  159. package/dist/svelte/components/CommissionExpenseSummary.svelte +186 -0
  160. package/dist/svelte/components/CommissionExpenseSummary.svelte.d.ts +13 -0
  161. package/dist/svelte/components/CommissionExpenseSummary.svelte.d.ts.map +1 -0
  162. package/dist/svelte/components/ExecutedAgreementsList.svelte +136 -0
  163. package/dist/svelte/components/ExecutedAgreementsList.svelte.d.ts +11 -0
  164. package/dist/svelte/components/ExecutedAgreementsList.svelte.d.ts.map +1 -0
  165. package/dist/svelte/components/LeadList.svelte +224 -0
  166. package/dist/svelte/components/LeadList.svelte.d.ts +19 -0
  167. package/dist/svelte/components/LeadList.svelte.d.ts.map +1 -0
  168. package/dist/svelte/components/OpportunityBoard.svelte +230 -0
  169. package/dist/svelte/components/OpportunityBoard.svelte.d.ts +17 -0
  170. package/dist/svelte/components/OpportunityBoard.svelte.d.ts.map +1 -0
  171. package/dist/svelte/components/OpportunityDetail.svelte +472 -0
  172. package/dist/svelte/components/OpportunityDetail.svelte.d.ts +27 -0
  173. package/dist/svelte/components/OpportunityDetail.svelte.d.ts.map +1 -0
  174. package/dist/svelte/components/PayoutBatchReview.svelte +285 -0
  175. package/dist/svelte/components/PayoutBatchReview.svelte.d.ts +21 -0
  176. package/dist/svelte/components/PayoutBatchReview.svelte.d.ts.map +1 -0
  177. package/dist/svelte/components/PayoutHistoryList.svelte +245 -0
  178. package/dist/svelte/components/PayoutHistoryList.svelte.d.ts +11 -0
  179. package/dist/svelte/components/PayoutHistoryList.svelte.d.ts.map +1 -0
  180. package/dist/svelte/components/ReferralLinkManager.svelte +216 -0
  181. package/dist/svelte/components/ReferralLinkManager.svelte.d.ts +17 -0
  182. package/dist/svelte/components/ReferralLinkManager.svelte.d.ts.map +1 -0
  183. package/dist/svelte/components/ReferralStatusList.svelte +118 -0
  184. package/dist/svelte/components/ReferralStatusList.svelte.d.ts +11 -0
  185. package/dist/svelte/components/ReferralStatusList.svelte.d.ts.map +1 -0
  186. package/dist/svelte/components/ReferrerEarningsSummary.svelte +106 -0
  187. package/dist/svelte/components/ReferrerEarningsSummary.svelte.d.ts +11 -0
  188. package/dist/svelte/components/ReferrerEarningsSummary.svelte.d.ts.map +1 -0
  189. package/dist/svelte/components/SalesDashboard.svelte +192 -0
  190. package/dist/svelte/components/SalesDashboard.svelte.d.ts +29 -0
  191. package/dist/svelte/components/SalesDashboard.svelte.d.ts.map +1 -0
  192. package/dist/svelte/format.d.ts +46 -0
  193. package/dist/svelte/format.d.ts.map +1 -0
  194. package/dist/svelte/format.js +75 -0
  195. package/dist/svelte/index.d.ts +50 -0
  196. package/dist/svelte/index.d.ts.map +1 -0
  197. package/dist/svelte/index.js +37 -0
  198. package/dist/svelte/types.d.ts +422 -0
  199. package/dist/svelte/types.d.ts.map +1 -0
  200. package/dist/svelte/types.js +376 -0
  201. package/package.json +89 -0
@@ -0,0 +1,17 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { AttributionException } from '../models/AttributionException.js';
3
+ export declare class AttributionExceptionCollection extends SmrtCollection<AttributionException> {
4
+ static readonly _itemClass: typeof AttributionException;
5
+ /** Every open exception, oldest first (the review queue). */
6
+ findOpen(): Promise<AttributionException[]>;
7
+ /**
8
+ * The open exception for one target within one program, or `null`.
9
+ * `AttributionService.resolve()` returns this instead of minting a
10
+ * duplicate when a conflict is already parked for review.
11
+ */
12
+ findOpenByTarget(targetKind: string, targetId: string, programId: string): Promise<AttributionException | null>;
13
+ /** Every exception (open and resolved) for one target, newest first. */
14
+ findByTarget(targetKind: string, targetId: string): Promise<AttributionException[]>;
15
+ }
16
+ export default AttributionExceptionCollection;
17
+ //# sourceMappingURL=AttributionExceptionCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributionExceptionCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/AttributionExceptionCollection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,qBAAa,8BAA+B,SAAQ,cAAc,CAAC,oBAAoB,CAAC;IACtF,MAAM,CAAC,QAAQ,CAAC,UAAU,8BAAwB;IAElD,6DAA6D;IACvD,QAAQ,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAOjD;;;;OAIG;IACG,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IASvC,wEAAwE;IAClE,YAAY,CAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,oBAAoB,EAAE,CAAC;CAMnC;AAED,eAAe,8BAA8B,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { AttributionPolicy } from '../models/AttributionPolicy.js';
3
+ import { AttributionConflictBehavior, AttributionCreditMode, AttributionPolicyStatus } from '../types.js';
4
+ /**
5
+ * Fields an amendment may change relative to the version it copies.
6
+ * `policyKey` is fixed (it identifies the policy), `version` is computed,
7
+ * and `status` is always `draft` — a caller cannot mint a pre-activated
8
+ * amendment.
9
+ */
10
+ export interface AttributionPolicyAmendmentChanges {
11
+ windowDays?: number;
12
+ creditMode?: AttributionCreditMode;
13
+ conflictBehavior?: AttributionConflictBehavior;
14
+ allowSelfReferral?: boolean;
15
+ allowExistingClients?: boolean;
16
+ eligibleServices?: string[];
17
+ eligibleCampaigns?: string[];
18
+ eligibleRegions?: string[];
19
+ effectiveFrom?: Date | null;
20
+ metadata?: Record<string, unknown>;
21
+ }
22
+ export declare class AttributionPolicyCollection extends SmrtCollection<AttributionPolicy> {
23
+ static readonly _itemClass: typeof AttributionPolicy;
24
+ /** Every version of a policy, newest version first. */
25
+ findByPolicyKey(policyKey: string): Promise<AttributionPolicy[]>;
26
+ /** Policies by status. */
27
+ findByStatus(status: AttributionPolicyStatus): Promise<AttributionPolicy[]>;
28
+ /**
29
+ * The highest ACTIVE version of a policy already IN EFFECT at `at`, or
30
+ * `null` when none is. This is what `AttributionService.resolve()` loads
31
+ * when the caller doesn't pin a version. A future-dated amendment can be
32
+ * activated ahead of its effective date without governing attributions
33
+ * resolved before it takes effect (`effectiveFrom: null` = effective
34
+ * immediately).
35
+ */
36
+ latestActiveByKey(policyKey: string, at?: Date, tenantId?: string | null): Promise<AttributionPolicy | null>;
37
+ /**
38
+ * Create an amendment: insert a new DRAFT row with
39
+ * `version = max(existing versions) + 1`, copying the latest existing
40
+ * version's fields and then applying `changes`. The source version is not
41
+ * touched — activate the draft (and supersede the prior active version)
42
+ * as a separate, explicit step.
43
+ *
44
+ * Throws when no version of `policyKey` exists (nothing to amend — use
45
+ * `create` for a brand-new policy).
46
+ */
47
+ createAmendment(policyKey: string, changes?: AttributionPolicyAmendmentChanges): Promise<AttributionPolicy>;
48
+ }
49
+ export default AttributionPolicyCollection;
50
+ //# sourceMappingURL=AttributionPolicyCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributionPolicyCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/AttributionPolicyCollection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EACV,2BAA2B,EAC3B,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,WAAW,iCAAiC;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,gBAAgB,CAAC,EAAE,2BAA2B,CAAC;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qBAAa,2BAA4B,SAAQ,cAAc,CAAC,iBAAiB,CAAC;IAChF,MAAM,CAAC,QAAQ,CAAC,UAAU,2BAAqB;IAE/C,uDAAuD;IACjD,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAOtE,0BAA0B;IACpB,YAAY,CAChB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAO/B;;;;;;;OAOG;IACG,iBAAiB,CACrB,SAAS,EAAE,MAAM,EACjB,EAAE,GAAE,IAAiB,EACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAsBpC;;;;;;;;;OASG;IACG,eAAe,CACnB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,iCAAsC,GAC9C,OAAO,CAAC,iBAAiB,CAAC;CA2C9B;AAED,eAAe,2BAA2B,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { ReferralAgreement } from '../models/ReferralAgreement.js';
3
+ import { ReferralAgreementApprovalMode } from '../types.js';
4
+ /**
5
+ * Fields an amendment may change relative to the version it copies.
6
+ * `referrerId`/`programId` are fixed (they identify the agreement),
7
+ * `version` is computed, and `status` is always `draft`.
8
+ */
9
+ export interface ReferralAgreementAmendmentChanges {
10
+ commissionPlanKey?: string;
11
+ commissionPlanVersion?: number;
12
+ clearingDays?: number;
13
+ approvalMode?: ReferralAgreementApprovalMode;
14
+ effectiveFrom?: Date | null;
15
+ effectiveTo?: Date | null;
16
+ contractRef?: string;
17
+ executedArtifactUrl?: string;
18
+ executedArtifactHash?: string;
19
+ acceptanceEvidence?: Record<string, unknown>;
20
+ metadata?: Record<string, unknown>;
21
+ }
22
+ export declare class ReferralAgreementCollection extends SmrtCollection<ReferralAgreement> {
23
+ static readonly _itemClass: typeof ReferralAgreement;
24
+ /** Every version of one referrer+program agreement, newest version first. */
25
+ findByReferrerAndProgram(referrerId: string, programId: string): Promise<ReferralAgreement[]>;
26
+ /**
27
+ * The agreement governing `(referrerId, programId)` at instant `at`
28
+ * (default now): status `active` AND effective window containing `at`
29
+ * (`effectiveFrom` null = always started; `effectiveTo` null =
30
+ * open-ended). When several active versions overlap — transitional states
31
+ * during amendment activation — the highest version wins. `null` when
32
+ * nothing governs.
33
+ */
34
+ activeFor(referrerId: string, programId: string, at?: Date): Promise<ReferralAgreement | null>;
35
+ /**
36
+ * Create an amendment: insert a new DRAFT row with
37
+ * `version = max(existing versions) + 1`, copying the latest existing
38
+ * version's fields and then applying `changes`. The source version is not
39
+ * touched — activate the draft (and supersede the prior active version)
40
+ * as a separate, explicit step.
41
+ *
42
+ * Throws when no version exists for the pair (nothing to amend — use
43
+ * `create` for a brand-new agreement).
44
+ */
45
+ createAmendment(referrerId: string, programId: string, changes?: ReferralAgreementAmendmentChanges): Promise<ReferralAgreement>;
46
+ }
47
+ export default ReferralAgreementCollection;
48
+ //# sourceMappingURL=ReferralAgreementCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralAgreementCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/ReferralAgreementCollection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAEjE;;;;GAIG;AACH,MAAM,WAAW,iCAAiC;IAChD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,6BAA6B,CAAC;IAC7C,aAAa,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qBAAa,2BAA4B,SAAQ,cAAc,CAAC,iBAAiB,CAAC;IAChF,MAAM,CAAC,QAAQ,CAAC,UAAU,2BAAqB;IAE/C,6EAA6E;IACvE,wBAAwB,CAC5B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAO/B;;;;;;;OAOG;IACG,SAAS,CACb,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,EAAE,GAAE,IAAiB,GACpB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAQpC;;;;;;;;;OASG;IACG,eAAe,CACnB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,iCAAsC,GAC9C,OAAO,CAAC,iBAAiB,CAAC;CA4C9B;AAED,eAAe,2BAA2B,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { Referral } from '../models/Referral.js';
3
+ export declare class ReferralCollection extends SmrtCollection<Referral> {
4
+ static readonly _itemClass: typeof Referral;
5
+ /** All referrals credited to a referrer, newest first. */
6
+ findByReferrer(referrerId: string): Promise<Referral[]>;
7
+ /** All referrals pointing at one qualifying target, newest first. */
8
+ findByTarget(targetKind: string, targetId: string): Promise<Referral[]>;
9
+ /**
10
+ * QUALIFIED referrals for one target — what
11
+ * `ReferralCommissionService.processEarningEvent` resolves when given a
12
+ * target instead of explicit referral ids.
13
+ */
14
+ findQualifiedByTarget(targetKind: string, targetId: string): Promise<Referral[]>;
15
+ /**
16
+ * Expire lapsed attributions: every `attributed` referral whose
17
+ * `expiresAt` is set and `<= now` transitions to `expired` and is saved.
18
+ * Referrals without an `expiresAt` never lapse.
19
+ *
20
+ * @returns The referrals expired by this sweep.
21
+ */
22
+ sweepExpired(now?: Date): Promise<Referral[]>;
23
+ }
24
+ export default ReferralCollection;
25
+ //# sourceMappingURL=ReferralCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/ReferralCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,qBAAa,kBAAmB,SAAQ,cAAc,CAAC,QAAQ,CAAC;IAC9D,MAAM,CAAC,QAAQ,CAAC,UAAU,kBAAY;IAEtC,0DAA0D;IACpD,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAO7D,qEAAqE;IAC/D,YAAY,CAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,QAAQ,EAAE,CAAC;IAOtB;;;;OAIG;IACG,qBAAqB,CACzB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,QAAQ,EAAE,CAAC;IAOtB;;;;;;OAMG;IACG,YAAY,CAAC,GAAG,GAAE,IAAiB,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAiBhE;AAED,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { ReferralLink } from '../models/ReferralLink.js';
3
+ import { ReferralTouch } from '../models/ReferralTouch.js';
4
+ /** Length of generated share codes. */
5
+ export declare const REFERRAL_CODE_LENGTH = 10;
6
+ /** Alphabet generated codes draw from (lowercase alphanumeric). */
7
+ export declare const REFERRAL_CODE_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
8
+ /** Attempts before {@link ReferralLinkCollection.createWithUniqueCode} gives up. */
9
+ export declare const MAX_CODE_GENERATION_ATTEMPTS = 5;
10
+ /**
11
+ * Generate a crypto-random share code: {@link REFERRAL_CODE_LENGTH}
12
+ * characters drawn uniformly from {@link REFERRAL_CODE_ALPHABET} via
13
+ * rejection-sampled `crypto.randomBytes` (no modulo bias).
14
+ */
15
+ export declare function generateReferralCode(): string;
16
+ /** Input for {@link ReferralLinkCollection.createWithUniqueCode}. */
17
+ export interface CreateReferralLinkInput {
18
+ referrerId: string;
19
+ programId: string;
20
+ targetUrl?: string;
21
+ label?: string;
22
+ tenantId?: string | null;
23
+ /**
24
+ * Test seam / customization point: overrides the random code generator.
25
+ * Must return {@link REFERRAL_CODE_LENGTH} lowercase-alphanumeric
26
+ * characters; collisions with existing codes are retried up to
27
+ * {@link MAX_CODE_GENERATION_ATTEMPTS} times.
28
+ */
29
+ generateCode?: () => string;
30
+ }
31
+ /** Why {@link ReferralLinkCollection.recordClick} refused to record. */
32
+ export type RecordClickRefusal = 'unknown_code' | 'link_disabled';
33
+ /**
34
+ * Result of {@link ReferralLinkCollection.recordClick}. On success `link`
35
+ * and `touch` are both set and `refused` is absent. On refusal `touch` is
36
+ * `null`, `refused` names the reason, and `link` carries the (disabled) link
37
+ * for `'link_disabled'` / `null` for `'unknown_code'`.
38
+ */
39
+ export interface RecordClickResult {
40
+ link: ReferralLink | null;
41
+ touch: ReferralTouch | null;
42
+ refused?: RecordClickRefusal;
43
+ }
44
+ /** Input for {@link ReferralLinkCollection.recordClick}. */
45
+ export interface RecordClickInput {
46
+ code: string;
47
+ /** Extra evidence merged into the touch's evidence JSON (UA, IP hash, …). */
48
+ evidence?: Record<string, unknown>;
49
+ /** When the click occurred; defaults to now. */
50
+ occurredAt?: Date;
51
+ /**
52
+ * Prospect identity when the edge already knows it (e.g. a logged-in
53
+ * visitor or a pre-created lead). Without a subject pair the touch is
54
+ * anonymous and `AttributionService.resolve` cannot gather it by subject —
55
+ * the intake handler must then append a second, identified touch once the
56
+ * prospect materializes (same `occurredAt` preserves credit ordering).
57
+ */
58
+ subjectKind?: string;
59
+ subjectId?: string;
60
+ }
61
+ export declare class ReferralLinkCollection extends SmrtCollection<ReferralLink> {
62
+ static readonly _itemClass: typeof ReferralLink;
63
+ /** All links for a referrer, newest first. */
64
+ findByReferrer(referrerId: string): Promise<ReferralLink[]>;
65
+ /**
66
+ * Look up a link by its globally unique code (codes are minted lowercase;
67
+ * the lookup normalizes case so shared codes survive re-typing).
68
+ */
69
+ findByCode(code: string): Promise<ReferralLink | null>;
70
+ /**
71
+ * Create a link with a freshly minted, uniqueness-checked code.
72
+ *
73
+ * Codes come from `crypto.randomBytes` mapped to
74
+ * {@link REFERRAL_CODE_LENGTH} lowercase-alphanumeric characters. The
75
+ * check-then-insert loop retries on collision up to
76
+ * {@link MAX_CODE_GENERATION_ATTEMPTS} times, then throws — at 36^10
77
+ * possible codes repeated collisions mean the generator is broken (or a
78
+ * test seam returns a constant), not bad luck.
79
+ */
80
+ createWithUniqueCode(input: CreateReferralLinkInput): Promise<ReferralLink>;
81
+ /**
82
+ * Record a click on a share code: find the ACTIVE link, increment its
83
+ * {@link ReferralLink.clickCount}, and write an immutable ReferralTouch
84
+ * (kind `'click'`, evidence carrying the code/link/url plus any caller
85
+ * evidence). Returns `{ link, touch }` on success.
86
+ *
87
+ * Refusals return a typed result instead of throwing (clicks arrive from
88
+ * the edge — an unknown or disabled code is an expected outcome, not an
89
+ * exception): `refused: 'unknown_code'` (no such code; `link: null`) or
90
+ * `refused: 'link_disabled'` (link exists but is disabled; the link is
91
+ * returned, nothing is written).
92
+ */
93
+ recordClick(input: RecordClickInput): Promise<RecordClickResult>;
94
+ }
95
+ export default ReferralLinkCollection;
96
+ //# sourceMappingURL=ReferralLinkCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralLinkCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/ReferralLinkCollection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAuB,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGhE,uCAAuC;AACvC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,mEAAmE;AACnE,eAAO,MAAM,sBAAsB,yCAAyC,CAAC;AAE7E,oFAAoF;AACpF,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAe7C;AAED,qEAAqE;AACrE,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAED,wEAAwE;AACxE,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG,eAAe,CAAC;AAElE;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,4DAA4D;AAC5D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,gDAAgD;IAChD,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,sBAAuB,SAAQ,cAAc,CAAC,YAAY,CAAC;IACtE,MAAM,CAAC,QAAQ,CAAC,UAAU,sBAAgB;IAE1C,8CAA8C;IACxC,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAOjE;;;OAGG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAU5D;;;;;;;;;OASG;IACG,oBAAoB,CACxB,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,YAAY,CAAC;IA+BxB;;;;;;;;;;;OAWG;IACG,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAuCvE;AAED,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { ReferralProgram } from '../models/ReferralProgram.js';
3
+ import { ReferralProgramStatus } from '../types.js';
4
+ export declare class ReferralProgramCollection extends SmrtCollection<ReferralProgram> {
5
+ static readonly _itemClass: typeof ReferralProgram;
6
+ /**
7
+ * Look up a program by its natural key within the ambient tenant scope
8
+ * (`(tenant_id, key)` is the conflict key, so under a tenant context the
9
+ * auto-filter narrows this to at most one row).
10
+ */
11
+ findByKey(key: string): Promise<ReferralProgram | null>;
12
+ /** Programs by status. */
13
+ findByStatus(status: ReferralProgramStatus): Promise<ReferralProgram[]>;
14
+ /** All active programs. */
15
+ findActive(): Promise<ReferralProgram[]>;
16
+ }
17
+ export default ReferralProgramCollection;
18
+ //# sourceMappingURL=ReferralProgramCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralProgramCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/ReferralProgramCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,qBAAa,yBAA0B,SAAQ,cAAc,CAAC,eAAe,CAAC;IAC5E,MAAM,CAAC,QAAQ,CAAC,UAAU,yBAAmB;IAE7C;;;;OAIG;IACG,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAK7D,0BAA0B;IACpB,YAAY,CAChB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,eAAe,EAAE,CAAC;IAO7B,2BAA2B;IACrB,UAAU,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAG/C;AAED,eAAe,yBAAyB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { ReferralTermSnapshot } from '../models/ReferralTermSnapshot.js';
3
+ export declare class ReferralTermSnapshotCollection extends SmrtCollection<ReferralTermSnapshot> {
4
+ static readonly _itemClass: typeof ReferralTermSnapshot;
5
+ /**
6
+ * Every snapshot minted for one referral, newest first — index 0 is the
7
+ * currently governing snapshot only if the referral's `snapshotId` says
8
+ * so (requalification keeps old rows as history).
9
+ */
10
+ findByReferral(referralId: string): Promise<ReferralTermSnapshot[]>;
11
+ }
12
+ export default ReferralTermSnapshotCollection;
13
+ //# sourceMappingURL=ReferralTermSnapshotCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralTermSnapshotCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/ReferralTermSnapshotCollection.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,qBAAa,8BAA+B,SAAQ,cAAc,CAAC,oBAAoB,CAAC;IACtF,MAAM,CAAC,QAAQ,CAAC,UAAU,8BAAwB;IAElD;;;;OAIG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;CAM1E;AAED,eAAe,8BAA8B,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { ReferralTouch } from '../models/ReferralTouch.js';
3
+ /** Input for {@link ReferralTouchCollection.findByTargetWindow}. */
4
+ export interface TouchWindowQuery {
5
+ subjectKind: string;
6
+ subjectId: string;
7
+ /** Restrict to one program's touches. */
8
+ programId: string;
9
+ /** Only touches occurring at or after this instant. */
10
+ since: Date;
11
+ }
12
+ export declare class ReferralTouchCollection extends SmrtCollection<ReferralTouch> {
13
+ static readonly _itemClass: typeof ReferralTouch;
14
+ /** All touches for a referrer, oldest first. */
15
+ findByReferrer(referrerId: string): Promise<ReferralTouch[]>;
16
+ /**
17
+ * Every touch recorded against one subject identity, oldest first —
18
+ * attribution's raw candidate stream.
19
+ */
20
+ findBySubject(subjectKind: string, subjectId: string): Promise<ReferralTouch[]>;
21
+ /**
22
+ * Touches for one subject within one program occurring at or after
23
+ * `since`, oldest first. The date bound is applied in memory after the
24
+ * indexed equality filters (sibling-module pattern — the semantics hold
25
+ * whether an adapter returns ISO strings or Dates).
26
+ */
27
+ findByTargetWindow(query: TouchWindowQuery): Promise<ReferralTouch[]>;
28
+ }
29
+ export default ReferralTouchCollection;
30
+ //# sourceMappingURL=ReferralTouchCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralTouchCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/ReferralTouchCollection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,oEAAoE;AACpE,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,KAAK,EAAE,IAAI,CAAC;CACb;AAED,qBAAa,uBAAwB,SAAQ,cAAc,CAAC,aAAa,CAAC;IACxE,MAAM,CAAC,QAAQ,CAAC,UAAU,uBAAiB;IAE3C,gDAAgD;IAC1C,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAOlE;;;OAGG;IACG,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,EAAE,CAAC;IAO3B;;;;;OAKG;IACG,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAa5E;AAED,eAAe,uBAAuB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { SmrtCollection } from '@happyvertical/smrt-core';
2
+ import { Referrer } from '../models/Referrer.js';
3
+ import { ReferrerStatus } from '../types.js';
4
+ export declare class ReferrerCollection extends SmrtCollection<Referrer> {
5
+ static readonly _itemClass: typeof Referrer;
6
+ /**
7
+ * Find referrer roles held by a given profile (a profile may hold the
8
+ * role in several tenants/contexts).
9
+ */
10
+ findByProfile(profileId: string): Promise<Referrer[]>;
11
+ /** Referrers by status. */
12
+ findByStatus(status: ReferrerStatus): Promise<Referrer[]>;
13
+ /** All active referrers (eligible for new links/agreements). */
14
+ findActive(): Promise<Referrer[]>;
15
+ }
16
+ export default ReferrerCollection;
17
+ //# sourceMappingURL=ReferrerCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferrerCollection.d.ts","sourceRoot":"","sources":["../../../src/referrals/collections/ReferrerCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,qBAAa,kBAAmB,SAAQ,cAAc,CAAC,QAAQ,CAAC;IAC9D,MAAM,CAAC,QAAQ,CAAC,UAAU,kBAAY;IAEtC;;;OAGG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAO3D,2BAA2B;IACrB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAO/D,gEAAgE;IAC1D,UAAU,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;CAGxC;AAED,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Referrals module of `@happyvertical/smrt-sales`.
3
+ *
4
+ * Referrers, ReferralPrograms, versioned AttributionPolicies, share
5
+ * links/codes, immutable ReferralTouch evidence, Referrals with guarded
6
+ * lifecycles, the AttributionException review queue, versioned
7
+ * ReferralAgreements, immutable ReferralTermSnapshots, and the services
8
+ * that connect them: attribution, qualification, and the commission bridge.
9
+ *
10
+ * This module depends on `../commissions` (same package) for the neutral
11
+ * financial core and NEVER on `../crm` — qualifying targets are generic
12
+ * `(targetKind, targetId)` string pairs (see `packages/sales/AGENTS.md`).
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ export { AttributionExceptionCollection } from './collections/AttributionExceptionCollection.js';
17
+ export { type AttributionPolicyAmendmentChanges, AttributionPolicyCollection, } from './collections/AttributionPolicyCollection.js';
18
+ export { type ReferralAgreementAmendmentChanges, ReferralAgreementCollection, } from './collections/ReferralAgreementCollection.js';
19
+ export { ReferralCollection } from './collections/ReferralCollection.js';
20
+ export { type CreateReferralLinkInput, generateReferralCode, MAX_CODE_GENERATION_ATTEMPTS, REFERRAL_CODE_ALPHABET, REFERRAL_CODE_LENGTH, type RecordClickInput, type RecordClickRefusal, type RecordClickResult, ReferralLinkCollection, } from './collections/ReferralLinkCollection.js';
21
+ export { ReferralProgramCollection } from './collections/ReferralProgramCollection.js';
22
+ export { ReferralTermSnapshotCollection } from './collections/ReferralTermSnapshotCollection.js';
23
+ export { ReferralTouchCollection, type TouchWindowQuery, } from './collections/ReferralTouchCollection.js';
24
+ export { ReferrerCollection } from './collections/ReferrerCollection.js';
25
+ export { AttributionException } from './models/AttributionException.js';
26
+ export { AttributionPolicy, validateAttributionPolicyTerms, } from './models/AttributionPolicy.js';
27
+ export { Referral } from './models/Referral.js';
28
+ export { ReferralAgreement } from './models/ReferralAgreement.js';
29
+ export { assertHttpTargetUrl, ReferralLink } from './models/ReferralLink.js';
30
+ export { ReferralProgram } from './models/ReferralProgram.js';
31
+ export { ReferralTermSnapshot } from './models/ReferralTermSnapshot.js';
32
+ export { ReferralTouch } from './models/ReferralTouch.js';
33
+ export { Referrer } from './models/Referrer.js';
34
+ export { type AttributionAward, type AttributionAwardResult, type AttributionRefusalReason, type AttributionResolution, AttributionService, type AttributionServiceDeps, type OverrideAttributionInput, QualifiedReferralOverrideError, type RecordManualAssignmentInput, type ResolveAttributionInput, type ResolveExceptionInput, } from './services/AttributionService.js';
35
+ export { type ProcessEarningEventInput, type ProcessEarningEventResult, REFERRAL_TERMS_SNAPSHOT_KIND, type ReferralCommissionOutcome, ReferralCommissionService, type ReferralCommissionServiceDeps, type ReferralProcessingSkip, type ReferralProcessingSkipReason, } from './services/ReferralCommissionService.js';
36
+ export { type QualificationRefusalReason, type QualifyReferralInput, type QualifyReferralResult, ReferralQualificationService, type ReferralQualificationServiceDeps, type RequalifyReferralInput, type RequalifyReferralResult, } from './services/ReferralQualificationService.js';
37
+ export * from './types.js';
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/referrals/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AACjG,OAAO,EACL,KAAK,iCAAiC,EACtC,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACL,KAAK,iCAAiC,EACtC,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EACL,KAAK,uBAAuB,EAC5B,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,sBAAsB,GACvB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AACjG,OAAO,EACL,uBAAuB,EACvB,KAAK,gBAAgB,GACtB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,kBAAkB,EAClB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,8BAA8B,EAC9B,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,4BAA4B,EAC5B,KAAK,yBAAyB,EAC9B,yBAAyB,EACzB,KAAK,6BAA6B,EAClC,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,GAClC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,4BAA4B,EAC5B,KAAK,gCAAgC,EACrC,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,4CAA4C,CAAC;AAEpD,cAAc,YAAY,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { SmrtObject } from '@happyvertical/smrt-core';
2
+ import { AttributionExceptionCandidate, AttributionExceptionOptions, AttributionExceptionStatus } from '../types.js';
3
+ export declare class AttributionException extends SmrtObject {
4
+ /** Tenant ID for multi-tenant isolation (nullable → global rows). */
5
+ tenantId: string | null;
6
+ /** Target the conflicting attribution is about. Required. */
7
+ targetKind: string;
8
+ /** Identifier within the {@link targetKind} namespace. Required. */
9
+ targetId: string;
10
+ /** The ReferralProgram the contention belongs to. */
11
+ programId: string;
12
+ /** `open` (default, awaiting review) or `resolved`. */
13
+ status: AttributionExceptionStatus;
14
+ /**
15
+ * Why the exception was raised — recommended vocabulary: `'tie'`
16
+ * (exact-timestamp tie between distinct referrers),
17
+ * `'competing_touches'` (competing manual assignments), and
18
+ * `'policy_review'` (`conflictBehavior: 'review'` with multiple
19
+ * referrers). Open string.
20
+ */
21
+ conflictReason: string;
22
+ /**
23
+ * The competing touches as a JSON-string array of
24
+ * {@link AttributionExceptionCandidate}. Use
25
+ * {@link getCandidates}/{@link setCandidates}.
26
+ */
27
+ candidates: string;
28
+ /**
29
+ * How the exception was resolved — `'override'` (human award) or
30
+ * `'policy'` (policy re-run). Empty while open.
31
+ */
32
+ resolutionMode: string;
33
+ /** Why credit was awarded the way it was. REQUIRED to resolve. */
34
+ resolutionReason: string;
35
+ /**
36
+ * Who resolved the exception — cross-package string reference to a
37
+ * smrt-profiles Profile.
38
+ */
39
+ resolvedByProfileId: string;
40
+ /**
41
+ * Ids of the Referral rows the resolution created, as a JSON-string
42
+ * array. Use {@link getResolvedReferralIds}/{@link setResolvedReferralIds}.
43
+ */
44
+ resolvedReferralIds: string;
45
+ /** When the exception was resolved. */
46
+ resolvedAt: Date | null;
47
+ /**
48
+ * Free-form JSON object stored as a string (the attribution service
49
+ * stamps the policy pin here for later resolution). Use
50
+ * {@link getMetadata}/{@link setMetadata}.
51
+ */
52
+ metadata: string;
53
+ constructor(options?: AttributionExceptionOptions);
54
+ /** Re-coerce date fields after the framework reapplies raw option values. */
55
+ initialize(): Promise<this>;
56
+ /** Whether the exception still awaits review. */
57
+ isOpen(): boolean;
58
+ /** Parse {@link candidates}; returns `[]` on empty/invalid JSON. */
59
+ getCandidates(): AttributionExceptionCandidate[];
60
+ /** Serialize and store {@link candidates}. */
61
+ setCandidates(candidates: AttributionExceptionCandidate[]): void;
62
+ /** Parse {@link resolvedReferralIds}; returns `[]` on empty/invalid JSON. */
63
+ getResolvedReferralIds(): string[];
64
+ /** Serialize and store {@link resolvedReferralIds}. */
65
+ setResolvedReferralIds(ids: string[]): void;
66
+ /** Parse {@link metadata}; returns `{}` on malformed content. */
67
+ getMetadata(): Record<string, unknown>;
68
+ /** Serialize and store {@link metadata}. */
69
+ setMetadata(data: Record<string, unknown>): void;
70
+ /**
71
+ * Mark the exception resolved (mutates; the caller saves). Requires a
72
+ * non-empty reason — resolutions without a recorded rationale are
73
+ * rejected.
74
+ */
75
+ markResolved(input: {
76
+ mode: string;
77
+ reason: string;
78
+ resolvedByProfileId?: string;
79
+ referralIds: string[];
80
+ at?: Date;
81
+ }): void;
82
+ private static coerceDate;
83
+ }
84
+ export default AttributionException;
85
+ //# sourceMappingURL=AttributionException.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributionException.d.ts","sourceRoot":"","sources":["../../../src/referrals/models/AttributionException.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAIL,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AAErB,qBAQa,oBAAqB,SAAQ,UAAU;IAClD,qEAAqE;IAErE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B,6DAA6D;IAE7D,UAAU,EAAE,MAAM,CAAM;IAExB,oEAAoE;IAEpE,QAAQ,EAAE,MAAM,CAAM;IAEtB,qDAAqD;IAErD,SAAS,EAAE,MAAM,CAAM;IAEvB,uDAAuD;IACvD,MAAM,EAAE,0BAA0B,CAAU;IAE5C;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAM;IAE5B;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAQ;IAE1B;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAM;IAE5B,kEAAkE;IAClE,gBAAgB,EAAE,MAAM,CAAM;IAE9B;;;OAGG;IAEH,mBAAmB,EAAE,MAAM,CAAM;IAEjC;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAQ;IAEnC,uCAAuC;IACvC,UAAU,EAAE,IAAI,GAAG,IAAI,CAAQ;IAE/B;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAQ;gBAEZ,OAAO,GAAE,2BAAgC;IAuBrD,6EAA6E;IAC9D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAM1C,iDAAiD;IACjD,MAAM,IAAI,OAAO;IAIjB,oEAAoE;IACpE,aAAa,IAAI,6BAA6B,EAAE;IAYhD,8CAA8C;IAC9C,aAAa,CAAC,UAAU,EAAE,6BAA6B,EAAE,GAAG,IAAI;IAIhE,6EAA6E;IAC7E,sBAAsB,IAAI,MAAM,EAAE;IAYlC,uDAAuD;IACvD,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI;IAI3C,iEAAiE;IACjE,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAYtC,4CAA4C;IAC5C,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIhD;;;;OAIG;IACH,YAAY,CAAC,KAAK,EAAE;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,EAAE,CAAC,EAAE,IAAI,CAAC;KACX,GAAG,IAAI;IAmBR,OAAO,CAAC,MAAM,CAAC,UAAU;CAS1B;AAED,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,128 @@
1
+ import { SmrtObject } from '@happyvertical/smrt-core';
2
+ import { AttributionConflictBehavior, AttributionCreditMode, AttributionPolicyOptions, AttributionPolicyStatus } from '../types.js';
3
+ /**
4
+ * Validate a policy's terms. Throws a descriptive error on the first
5
+ * violation. Called by {@link AttributionPolicy.activate} and by activating
6
+ * saves so no active policy can carry malformed terms.
7
+ */
8
+ export declare function validateAttributionPolicyTerms(policy: AttributionPolicy): void;
9
+ export declare class AttributionPolicy extends SmrtObject {
10
+ /** Tenant ID for multi-tenant isolation (nullable → global policies). */
11
+ tenantId: string | null;
12
+ /** Stable policy identity shared by every version of the policy. */
13
+ policyKey: string;
14
+ /** Monotonic version within `policyKey`. Amendments insert `max + 1`. */
15
+ version: number;
16
+ /**
17
+ * Lifecycle status — see {@link POLICY_STATUS_TRANSITIONS}. Mutate via
18
+ * {@link activate} / {@link supersede} / {@link retire} (or a legal
19
+ * single-step assignment; the save-time guard rejects illegal edges).
20
+ */
21
+ status: AttributionPolicyStatus;
22
+ /** When this version takes effect. Frozen once the policy activates. */
23
+ effectiveFrom: Date | null;
24
+ /**
25
+ * Attribution window in days: only touches occurring within `windowDays`
26
+ * of the resolution instant are credit candidates, and attributed
27
+ * referrals expire `windowDays` after attribution if never qualified.
28
+ */
29
+ windowDays: number;
30
+ /** How competing touches are credited. */
31
+ creditMode: AttributionCreditMode;
32
+ /** Whether multi-referrer contention auto-resolves or forces review. */
33
+ conflictBehavior: AttributionConflictBehavior;
34
+ /**
35
+ * Whether a touch whose referrer IS the prospect (matching
36
+ * `subjectProfileId`) may earn credit. Default false: self-referrals are
37
+ * dropped from candidate sets.
38
+ */
39
+ allowSelfReferral: boolean;
40
+ /**
41
+ * Whether referrals of already-existing clients are eligible. Default
42
+ * false: `AttributionService.resolve()` refuses outright when the caller
43
+ * flags the prospect as an existing client.
44
+ */
45
+ allowExistingClients: boolean;
46
+ /**
47
+ * Eligible service keys as a JSON-string array — empty array means ALL
48
+ * services are eligible. Interpretation belongs to the application layer
49
+ * that maps its offerings onto service keys; this module records and
50
+ * validates the list. Use {@link getEligibleServices}/{@link setEligibleServices}.
51
+ */
52
+ eligibleServices: string;
53
+ /** Eligible campaign keys (JSON-string array; empty = all eligible). */
54
+ eligibleCampaigns: string;
55
+ /** Eligible region codes (JSON-string array; empty = all eligible). */
56
+ eligibleRegions: string;
57
+ /** Additional metadata as a JSON string (not part of the frozen identity). */
58
+ metadata: string;
59
+ constructor(options?: AttributionPolicyOptions);
60
+ /**
61
+ * Re-coerce date fields after the framework reapplies raw option values,
62
+ * record the loaded status for the transition guard, and capture the
63
+ * frozen snapshot when the row arrived already non-draft (superseded and
64
+ * retired versions — history — can't be rewritten either).
65
+ */
66
+ initialize(): Promise<this>;
67
+ isDraft(): boolean;
68
+ isActive(): boolean;
69
+ /** Parse {@link eligibleServices}; returns `[]` on empty/invalid JSON. */
70
+ getEligibleServices(): string[];
71
+ /** Serialize and store {@link eligibleServices}. */
72
+ setEligibleServices(services: string[]): void;
73
+ /** Parse {@link eligibleCampaigns}; returns `[]` on empty/invalid JSON. */
74
+ getEligibleCampaigns(): string[];
75
+ /** Serialize and store {@link eligibleCampaigns}. */
76
+ setEligibleCampaigns(campaigns: string[]): void;
77
+ /** Parse {@link eligibleRegions}; returns `[]` on empty/invalid JSON. */
78
+ getEligibleRegions(): string[];
79
+ /** Serialize and store {@link eligibleRegions}. */
80
+ setEligibleRegions(regions: string[]): void;
81
+ /** Parse {@link metadata}; returns `{}` on empty/invalid JSON. */
82
+ getMetadata(): Record<string, unknown>;
83
+ /** Serialize and store {@link metadata}. */
84
+ setMetadata(data: Record<string, unknown>): void;
85
+ /**
86
+ * Transition `draft → active`. Validates the terms first so no active
87
+ * policy can carry malformed window/mode/eligibility values.
88
+ */
89
+ activate(): void;
90
+ /** Transition `active → superseded` (a newer version took over). */
91
+ supersede(): void;
92
+ /** Transition `draft | active → retired` (terminal). */
93
+ retire(): void;
94
+ /**
95
+ * Save with two guards (CommissionPlan pattern):
96
+ *
97
+ * 1. **Status transition** — the about-to-be-written status must be a
98
+ * legal edge from the authoritative prior persisted status (re-read
99
+ * from the DB so a `create({ id: <existing>, _skipLoad: true })` upsert
100
+ * can't sidestep the guard).
101
+ * 2. **Frozen policy identity** — once the row has been saved non-draft,
102
+ * every policy-defining field must match the captured snapshot. Amend
103
+ * by inserting a new version instead.
104
+ */
105
+ save(): Promise<this>;
106
+ /**
107
+ * Refuse a save whose `(tenantId, policyKey, version)` natural key
108
+ * already belongs to a DIFFERENT row — the frozen-identity guard is
109
+ * instance-local, so a fresh instance would otherwise upsert over the
110
+ * persisted policy (rewriting attribution rules and rotating the row
111
+ * id). Edit drafts by hydrating them; change terms with
112
+ * `AttributionPolicyCollection.createAmendment()`.
113
+ */
114
+ private assertNaturalKeyNotTaken;
115
+ /**
116
+ * Resolve the AUTHORITATIVE prior status from the database; fall back to
117
+ * the loaded-status WeakMap only when the DB is unavailable. `undefined`
118
+ * means no persisted row exists (genuinely new).
119
+ */
120
+ private resolvePriorStatus;
121
+ private assertStatusTransition;
122
+ private assertFrozenIdentityUnchanged;
123
+ private serializeFrozenSnapshot;
124
+ private static parseStringArray;
125
+ private static coerceDate;
126
+ }
127
+ export default AttributionPolicy;
128
+ //# sourceMappingURL=AttributionPolicy.d.ts.map