@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.
- package/AGENTS.md +87 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/__smrt-register__.d.ts +2 -0
- package/dist/__smrt-register__.d.ts.map +1 -0
- package/dist/chunks/__smrt-register__-kWdT7LOt.js +6 -0
- package/dist/chunks/__smrt-register__-kWdT7LOt.js.map +1 -0
- package/dist/chunks/commissions-BCxqOKVM.js +2181 -0
- package/dist/chunks/commissions-BCxqOKVM.js.map +1 -0
- package/dist/chunks/crm-DwEz7E2r.js +1428 -0
- package/dist/chunks/crm-DwEz7E2r.js.map +1 -0
- package/dist/chunks/referrals-BY47p70T.js +2880 -0
- package/dist/chunks/referrals-BY47p70T.js.map +1 -0
- package/dist/commissions/collections/CommissionAdjustmentCollection.d.ts +26 -0
- package/dist/commissions/collections/CommissionAdjustmentCollection.d.ts.map +1 -0
- package/dist/commissions/collections/CommissionCollection.d.ts +43 -0
- package/dist/commissions/collections/CommissionCollection.d.ts.map +1 -0
- package/dist/commissions/collections/CommissionPayoutCollection.d.ts +19 -0
- package/dist/commissions/collections/CommissionPayoutCollection.d.ts.map +1 -0
- package/dist/commissions/collections/CommissionPlanCollection.d.ts +46 -0
- package/dist/commissions/collections/CommissionPlanCollection.d.ts.map +1 -0
- package/dist/commissions/collections/EarnerCollection.d.ts +14 -0
- package/dist/commissions/collections/EarnerCollection.d.ts.map +1 -0
- package/dist/commissions/collections/EarningEventCollection.d.ts +27 -0
- package/dist/commissions/collections/EarningEventCollection.d.ts.map +1 -0
- package/dist/commissions/collections/index.d.ts +11 -0
- package/dist/commissions/collections/index.d.ts.map +1 -0
- package/dist/commissions/index.d.ts +20 -0
- package/dist/commissions/index.d.ts.map +1 -0
- package/dist/commissions/models/Commission.d.ts +150 -0
- package/dist/commissions/models/Commission.d.ts.map +1 -0
- package/dist/commissions/models/CommissionAdjustment.d.ts +62 -0
- package/dist/commissions/models/CommissionAdjustment.d.ts.map +1 -0
- package/dist/commissions/models/CommissionPayout.d.ts +119 -0
- package/dist/commissions/models/CommissionPayout.d.ts.map +1 -0
- package/dist/commissions/models/CommissionPlan.d.ts +117 -0
- package/dist/commissions/models/CommissionPlan.d.ts.map +1 -0
- package/dist/commissions/models/Earner.d.ts +49 -0
- package/dist/commissions/models/Earner.d.ts.map +1 -0
- package/dist/commissions/models/EarningEvent.d.ts +89 -0
- package/dist/commissions/models/EarningEvent.d.ts.map +1 -0
- package/dist/commissions/models/index.d.ts +11 -0
- package/dist/commissions/models/index.d.ts.map +1 -0
- package/dist/commissions/money.d.ts +42 -0
- package/dist/commissions/money.d.ts.map +1 -0
- package/dist/commissions/services/CommissionBalanceService.d.ts +14 -0
- package/dist/commissions/services/CommissionBalanceService.d.ts.map +1 -0
- package/dist/commissions/services/CommissionCalculationService.d.ts +142 -0
- package/dist/commissions/services/CommissionCalculationService.d.ts.map +1 -0
- package/dist/commissions/services/CommissionPayoutService.d.ts +134 -0
- package/dist/commissions/services/CommissionPayoutService.d.ts.map +1 -0
- package/dist/commissions/services/CommissionSettlementService.d.ts +42 -0
- package/dist/commissions/services/CommissionSettlementService.d.ts.map +1 -0
- package/dist/commissions/services/index.d.ts +9 -0
- package/dist/commissions/services/index.d.ts.map +1 -0
- package/dist/commissions/types.d.ts +243 -0
- package/dist/commissions/types.d.ts.map +1 -0
- package/dist/commissions.d.ts +2 -0
- package/dist/commissions.d.ts.map +1 -0
- package/dist/commissions.js +3 -0
- package/dist/crm/collections/LeadCollection.d.ts +79 -0
- package/dist/crm/collections/LeadCollection.d.ts.map +1 -0
- package/dist/crm/collections/OpportunityCollection.d.ts +42 -0
- package/dist/crm/collections/OpportunityCollection.d.ts.map +1 -0
- package/dist/crm/collections/OpportunityConversionCollection.d.ts +26 -0
- package/dist/crm/collections/OpportunityConversionCollection.d.ts.map +1 -0
- package/dist/crm/collections/PipelineDefinitionCollection.d.ts +46 -0
- package/dist/crm/collections/PipelineDefinitionCollection.d.ts.map +1 -0
- package/dist/crm/collections/PipelineStageCollection.d.ts +22 -0
- package/dist/crm/collections/PipelineStageCollection.d.ts.map +1 -0
- package/dist/crm/collections/SalesActivityCollection.d.ts +24 -0
- package/dist/crm/collections/SalesActivityCollection.d.ts.map +1 -0
- package/dist/crm/collections/SalesRepresentativeCollection.d.ts +19 -0
- package/dist/crm/collections/SalesRepresentativeCollection.d.ts.map +1 -0
- package/dist/crm/index.d.ts +27 -0
- package/dist/crm/index.d.ts.map +1 -0
- package/dist/crm/models/Lead.d.ts +135 -0
- package/dist/crm/models/Lead.d.ts.map +1 -0
- package/dist/crm/models/Opportunity.d.ts +111 -0
- package/dist/crm/models/Opportunity.d.ts.map +1 -0
- package/dist/crm/models/OpportunityConversion.d.ts +66 -0
- package/dist/crm/models/OpportunityConversion.d.ts.map +1 -0
- package/dist/crm/models/PipelineDefinition.d.ts +58 -0
- package/dist/crm/models/PipelineDefinition.d.ts.map +1 -0
- package/dist/crm/models/PipelineStage.d.ts +66 -0
- package/dist/crm/models/PipelineStage.d.ts.map +1 -0
- package/dist/crm/models/SalesActivity.d.ts +76 -0
- package/dist/crm/models/SalesActivity.d.ts.map +1 -0
- package/dist/crm/models/SalesRepresentative.d.ts +60 -0
- package/dist/crm/models/SalesRepresentative.d.ts.map +1 -0
- package/dist/crm/types.d.ts +228 -0
- package/dist/crm/types.d.ts.map +1 -0
- package/dist/crm.d.ts +2 -0
- package/dist/crm.d.ts.map +1 -0
- package/dist/crm.js +3 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/manifest.json +9340 -0
- package/dist/referrals/collections/AttributionExceptionCollection.d.ts +17 -0
- package/dist/referrals/collections/AttributionExceptionCollection.d.ts.map +1 -0
- package/dist/referrals/collections/AttributionPolicyCollection.d.ts +50 -0
- package/dist/referrals/collections/AttributionPolicyCollection.d.ts.map +1 -0
- package/dist/referrals/collections/ReferralAgreementCollection.d.ts +48 -0
- package/dist/referrals/collections/ReferralAgreementCollection.d.ts.map +1 -0
- package/dist/referrals/collections/ReferralCollection.d.ts +25 -0
- package/dist/referrals/collections/ReferralCollection.d.ts.map +1 -0
- package/dist/referrals/collections/ReferralLinkCollection.d.ts +96 -0
- package/dist/referrals/collections/ReferralLinkCollection.d.ts.map +1 -0
- package/dist/referrals/collections/ReferralProgramCollection.d.ts +18 -0
- package/dist/referrals/collections/ReferralProgramCollection.d.ts.map +1 -0
- package/dist/referrals/collections/ReferralTermSnapshotCollection.d.ts +13 -0
- package/dist/referrals/collections/ReferralTermSnapshotCollection.d.ts.map +1 -0
- package/dist/referrals/collections/ReferralTouchCollection.d.ts +30 -0
- package/dist/referrals/collections/ReferralTouchCollection.d.ts.map +1 -0
- package/dist/referrals/collections/ReferrerCollection.d.ts +17 -0
- package/dist/referrals/collections/ReferrerCollection.d.ts.map +1 -0
- package/dist/referrals/index.d.ts +38 -0
- package/dist/referrals/index.d.ts.map +1 -0
- package/dist/referrals/models/AttributionException.d.ts +85 -0
- package/dist/referrals/models/AttributionException.d.ts.map +1 -0
- package/dist/referrals/models/AttributionPolicy.d.ts +128 -0
- package/dist/referrals/models/AttributionPolicy.d.ts.map +1 -0
- package/dist/referrals/models/Referral.d.ts +112 -0
- package/dist/referrals/models/Referral.d.ts.map +1 -0
- package/dist/referrals/models/ReferralAgreement.d.ts +125 -0
- package/dist/referrals/models/ReferralAgreement.d.ts.map +1 -0
- package/dist/referrals/models/ReferralLink.d.ts +71 -0
- package/dist/referrals/models/ReferralLink.d.ts.map +1 -0
- package/dist/referrals/models/ReferralProgram.d.ts +57 -0
- package/dist/referrals/models/ReferralProgram.d.ts.map +1 -0
- package/dist/referrals/models/ReferralTermSnapshot.d.ts +61 -0
- package/dist/referrals/models/ReferralTermSnapshot.d.ts.map +1 -0
- package/dist/referrals/models/ReferralTouch.d.ts +55 -0
- package/dist/referrals/models/ReferralTouch.d.ts.map +1 -0
- package/dist/referrals/models/Referrer.d.ts +69 -0
- package/dist/referrals/models/Referrer.d.ts.map +1 -0
- package/dist/referrals/services/AttributionService.d.ts +248 -0
- package/dist/referrals/services/AttributionService.d.ts.map +1 -0
- package/dist/referrals/services/ReferralCommissionService.d.ts +91 -0
- package/dist/referrals/services/ReferralCommissionService.d.ts.map +1 -0
- package/dist/referrals/services/ReferralQualificationService.d.ts +135 -0
- package/dist/referrals/services/ReferralQualificationService.d.ts.map +1 -0
- package/dist/referrals/types.d.ts +226 -0
- package/dist/referrals/types.d.ts.map +1 -0
- package/dist/referrals.d.ts +2 -0
- package/dist/referrals.d.ts.map +1 -0
- package/dist/referrals.js +3 -0
- package/dist/smrt-knowledge.json +5501 -0
- package/dist/svelte/__tests__/format.test.js +68 -0
- package/dist/svelte/__tests__/types.test.js +349 -0
- package/dist/svelte/components/AttributionConflictQueue.svelte +361 -0
- package/dist/svelte/components/AttributionConflictQueue.svelte.d.ts +15 -0
- package/dist/svelte/components/AttributionConflictQueue.svelte.d.ts.map +1 -0
- package/dist/svelte/components/CommissionBreakdown.svelte +251 -0
- package/dist/svelte/components/CommissionBreakdown.svelte.d.ts +11 -0
- package/dist/svelte/components/CommissionBreakdown.svelte.d.ts.map +1 -0
- package/dist/svelte/components/CommissionExpenseSummary.svelte +186 -0
- package/dist/svelte/components/CommissionExpenseSummary.svelte.d.ts +13 -0
- package/dist/svelte/components/CommissionExpenseSummary.svelte.d.ts.map +1 -0
- package/dist/svelte/components/ExecutedAgreementsList.svelte +136 -0
- package/dist/svelte/components/ExecutedAgreementsList.svelte.d.ts +11 -0
- package/dist/svelte/components/ExecutedAgreementsList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/LeadList.svelte +224 -0
- package/dist/svelte/components/LeadList.svelte.d.ts +19 -0
- package/dist/svelte/components/LeadList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/OpportunityBoard.svelte +230 -0
- package/dist/svelte/components/OpportunityBoard.svelte.d.ts +17 -0
- package/dist/svelte/components/OpportunityBoard.svelte.d.ts.map +1 -0
- package/dist/svelte/components/OpportunityDetail.svelte +472 -0
- package/dist/svelte/components/OpportunityDetail.svelte.d.ts +27 -0
- package/dist/svelte/components/OpportunityDetail.svelte.d.ts.map +1 -0
- package/dist/svelte/components/PayoutBatchReview.svelte +285 -0
- package/dist/svelte/components/PayoutBatchReview.svelte.d.ts +21 -0
- package/dist/svelte/components/PayoutBatchReview.svelte.d.ts.map +1 -0
- package/dist/svelte/components/PayoutHistoryList.svelte +245 -0
- package/dist/svelte/components/PayoutHistoryList.svelte.d.ts +11 -0
- package/dist/svelte/components/PayoutHistoryList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/ReferralLinkManager.svelte +216 -0
- package/dist/svelte/components/ReferralLinkManager.svelte.d.ts +17 -0
- package/dist/svelte/components/ReferralLinkManager.svelte.d.ts.map +1 -0
- package/dist/svelte/components/ReferralStatusList.svelte +118 -0
- package/dist/svelte/components/ReferralStatusList.svelte.d.ts +11 -0
- package/dist/svelte/components/ReferralStatusList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/ReferrerEarningsSummary.svelte +106 -0
- package/dist/svelte/components/ReferrerEarningsSummary.svelte.d.ts +11 -0
- package/dist/svelte/components/ReferrerEarningsSummary.svelte.d.ts.map +1 -0
- package/dist/svelte/components/SalesDashboard.svelte +192 -0
- package/dist/svelte/components/SalesDashboard.svelte.d.ts +29 -0
- package/dist/svelte/components/SalesDashboard.svelte.d.ts.map +1 -0
- package/dist/svelte/format.d.ts +46 -0
- package/dist/svelte/format.d.ts.map +1 -0
- package/dist/svelte/format.js +75 -0
- package/dist/svelte/index.d.ts +50 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +37 -0
- package/dist/svelte/types.d.ts +422 -0
- package/dist/svelte/types.d.ts.map +1 -0
- package/dist/svelte/types.js +376 -0
- package/package.json +89 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
2
|
+
import { CommissionCollection } from '../collections/CommissionCollection.js';
|
|
3
|
+
import { Commission } from '../models/Commission.js';
|
|
4
|
+
export declare class CommissionSettlementService {
|
|
5
|
+
private readonly commissions;
|
|
6
|
+
constructor(commissions: CommissionCollection);
|
|
7
|
+
static create(classOptions?: SmrtClassOptions): Promise<CommissionSettlementService>;
|
|
8
|
+
/**
|
|
9
|
+
* Sweep the clearing window: every `pending` commission whose
|
|
10
|
+
* `clearingEndsAt` is `<= now` — or whose `clearingEndsAt` is `null`
|
|
11
|
+
* (null means NO clearing window applies, so the row is immediately
|
|
12
|
+
* sweepable) — transitions to `earned` and is saved.
|
|
13
|
+
*
|
|
14
|
+
* @returns The commissions that were marked earned by this sweep.
|
|
15
|
+
*/
|
|
16
|
+
sweepClearing(now?: Date): Promise<Commission[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Approve `earned` commissions by id (`earned → approved`). Strict: a
|
|
19
|
+
* missing id or a commission in any other status throws — the caller
|
|
20
|
+
* names exact rows, so a mismatch is a bug worth surfacing, not skipping.
|
|
21
|
+
*/
|
|
22
|
+
approveCommissions(ids: string[], now?: Date): Promise<Commission[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Release `approved` commissions to `payable` by id. Strict — see
|
|
25
|
+
* {@link approveCommissions}.
|
|
26
|
+
*/
|
|
27
|
+
markPayable(ids: string[], now?: Date): Promise<Commission[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Convenience chain: advance each commission from wherever it currently
|
|
30
|
+
* sits up to `payable` (`pending → earned → approved → payable`), saving
|
|
31
|
+
* after EACH step — the save-time guard only admits single-step edges, so
|
|
32
|
+
* every intermediate state is persisted (each with its timestamp). Rows
|
|
33
|
+
* already `payable` or `paid` are returned untouched (idempotent). Note
|
|
34
|
+
* this deliberately bypasses the clearing window — it's the "operator
|
|
35
|
+
* says pay these now" path.
|
|
36
|
+
*/
|
|
37
|
+
settleUpToPayable(ids: string[], now?: Date): Promise<Commission[]>;
|
|
38
|
+
private transitionByIds;
|
|
39
|
+
private requireCommission;
|
|
40
|
+
}
|
|
41
|
+
export default CommissionSettlementService;
|
|
42
|
+
//# sourceMappingURL=CommissionSettlementService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommissionSettlementService.d.ts","sourceRoot":"","sources":["../../../src/commissions/services/CommissionSettlementService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,qBAAa,2BAA2B;IAC1B,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,oBAAoB;WAEjD,MAAM,CACjB,YAAY,GAAE,gBAAqB,GAClC,OAAO,CAAC,2BAA2B,CAAC;IAMvC;;;;;;;OAOG;IACG,aAAa,CAAC,GAAG,GAAE,IAAiB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAelE;;;;OAIG;IACG,kBAAkB,CACtB,GAAG,EAAE,MAAM,EAAE,EACb,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,UAAU,EAAE,CAAC;IAMxB;;;OAGG;IACG,WAAW,CACf,GAAG,EAAE,MAAM,EAAE,EACb,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,UAAU,EAAE,CAAC;IAMxB;;;;;;;;OAQG;IACG,iBAAiB,CACrB,GAAG,EAAE,MAAM,EAAE,EACb,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,UAAU,EAAE,CAAC;YAqBV,eAAe;YAiBf,iBAAiB;CAShC;AAED,eAAe,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service barrel for the commissions module.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
export { CommissionBalanceService } from './CommissionBalanceService.js';
|
|
6
|
+
export { type CommissionCalculationInput, type CommissionCalculationResult, CommissionCalculationService, type CommissionComponentSkip, } from './CommissionCalculationService.js';
|
|
7
|
+
export { CommissionPayoutService, type CommissionPayoutServiceDeps, type CreatePayoutBatchInput, type CreatePayoutBatchResult, } from './CommissionPayoutService.js';
|
|
8
|
+
export { CommissionSettlementService } from './CommissionSettlementService.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commissions/services/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,4BAA4B,EAC5B,KAAK,uBAAuB,GAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,uBAAuB,EACvB,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { SmrtObjectOptions } from '@happyvertical/smrt-core';
|
|
2
|
+
/** Lifecycle of an {@link Earner} payout account. */
|
|
3
|
+
export declare const EARNER_STATUSES: readonly ["pending", "active", "suspended"];
|
|
4
|
+
export type EarnerStatus = (typeof EARNER_STATUSES)[number];
|
|
5
|
+
/**
|
|
6
|
+
* How a payout is delivered. Shared between {@link Earner} (preference) and
|
|
7
|
+
* {@link CommissionPayout} (what a specific batch will use).
|
|
8
|
+
*/
|
|
9
|
+
export declare const PAYOUT_METHODS: readonly ["bank_transfer", "check", "paypal", "credit", "other"];
|
|
10
|
+
export type PayoutMethod = (typeof PAYOUT_METHODS)[number];
|
|
11
|
+
/**
|
|
12
|
+
* Lifecycle of a versioned {@link CommissionPlan} row.
|
|
13
|
+
*
|
|
14
|
+
* `draft → active | retired`; `active → superseded | retired`;
|
|
15
|
+
* `superseded` / `retired` are terminal. Amendments never mutate an active
|
|
16
|
+
* row — they insert a new `(planKey, version + 1)` draft.
|
|
17
|
+
*/
|
|
18
|
+
export declare const COMMISSION_PLAN_STATUSES: readonly ["draft", "active", "superseded", "retired"];
|
|
19
|
+
export type CommissionPlanStatus = (typeof COMMISSION_PLAN_STATUSES)[number];
|
|
20
|
+
/**
|
|
21
|
+
* Lifecycle of a {@link Commission} earning record. STRICT forward chain:
|
|
22
|
+
* `pending → earned → approved → payable → paid` — no skips, no reversals.
|
|
23
|
+
* Corrections to earned/paid commissions are appended as
|
|
24
|
+
* {@link CommissionAdjustment} rows, never edits.
|
|
25
|
+
*/
|
|
26
|
+
export declare const COMMISSION_STATUSES: readonly ["pending", "earned", "approved", "payable", "paid"];
|
|
27
|
+
export type CommissionStatus = (typeof COMMISSION_STATUSES)[number];
|
|
28
|
+
/** How a commission amount is derived from its earning event. */
|
|
29
|
+
export declare const COMMISSION_BASES: readonly ["fixed", "gross", "net", "margin", "custom"];
|
|
30
|
+
export type CommissionBasis = (typeof COMMISSION_BASES)[number];
|
|
31
|
+
/** Kinds of append-only {@link CommissionAdjustment} corrections. */
|
|
32
|
+
export declare const COMMISSION_ADJUSTMENT_KINDS: readonly ["refund", "credit", "chargeback", "dispute", "correction"];
|
|
33
|
+
export type CommissionAdjustmentKind = (typeof COMMISSION_ADJUSTMENT_KINDS)[number];
|
|
34
|
+
/**
|
|
35
|
+
* Lifecycle of a {@link CommissionPayout} settlement batch.
|
|
36
|
+
*
|
|
37
|
+
* `pending → approved → processing → completed | failed`, with `failed`
|
|
38
|
+
* reachable from `approved`/`processing` and resettable to `pending` only via
|
|
39
|
+
* the dedicated `resetFromFailed()` helper.
|
|
40
|
+
*/
|
|
41
|
+
export declare const COMMISSION_PAYOUT_STATUSES: readonly ["pending", "approved", "processing", "completed", "failed"];
|
|
42
|
+
export type CommissionPayoutStatus = (typeof COMMISSION_PAYOUT_STATUSES)[number];
|
|
43
|
+
/**
|
|
44
|
+
* Recommended earning-event kinds. The `EarningEvent.eventKind` field stays an
|
|
45
|
+
* open string so applications can define their own commercial vocabulary —
|
|
46
|
+
* these are the kinds the framework's own modules emit and recognize.
|
|
47
|
+
*/
|
|
48
|
+
export declare const EARNING_EVENT_KINDS: readonly ["conversion", "agreement_execution", "invoice_payment", "collected_revenue", "recognized_margin", "milestone"];
|
|
49
|
+
export type EarningEventKind = (typeof EARNING_EVENT_KINDS)[number];
|
|
50
|
+
/**
|
|
51
|
+
* Commission statuses whose unsettled adjustments count toward an earner's
|
|
52
|
+
* net payable balance (and are gathered into payout batches). Adjustments
|
|
53
|
+
* against a still-`pending` commission stay out of settlement until the
|
|
54
|
+
* underlying earning clears.
|
|
55
|
+
*/
|
|
56
|
+
export declare const ADJUSTMENT_SETTLEABLE_COMMISSION_STATUSES: readonly ["earned", "approved", "payable", "paid"];
|
|
57
|
+
/** Recurrence contract for a {@link CommissionPlanComponent}. */
|
|
58
|
+
export interface CommissionPlanComponentRecurrence {
|
|
59
|
+
/** `one_time` fires at most once per earner+terms; `recurring` repeats. */
|
|
60
|
+
kind: 'one_time' | 'recurring';
|
|
61
|
+
/** Maximum number of occurrences for `recurring` components. */
|
|
62
|
+
maxOccurrences?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Only events whose `occurredAt` falls within `anchorAt + windowMonths`
|
|
65
|
+
* qualify (the anchor — e.g. an agreement's effective date — is supplied by
|
|
66
|
+
* the caller at calculation time).
|
|
67
|
+
*/
|
|
68
|
+
windowMonths?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* One calculation term inside a {@link CommissionPlan}'s `components` JSON
|
|
72
|
+
* array. Each earning event is matched against every component whose
|
|
73
|
+
* `trigger` equals the event's `eventKind` (or `'*'`).
|
|
74
|
+
*/
|
|
75
|
+
export interface CommissionPlanComponent {
|
|
76
|
+
/** Unique key within the plan (stable across versions by convention). */
|
|
77
|
+
key: string;
|
|
78
|
+
/** Earning-event kind this component fires on, or `'*'` for any kind. */
|
|
79
|
+
trigger: string;
|
|
80
|
+
/** How the commission base amount is resolved from the event. */
|
|
81
|
+
basis: CommissionBasis;
|
|
82
|
+
/** Rate in the range 0–1. Required for every basis except `fixed`. */
|
|
83
|
+
rate?: number;
|
|
84
|
+
/** Flat amount in integer cents. Required for basis `fixed`. */
|
|
85
|
+
fixedAmountCents?: number;
|
|
86
|
+
/** Optional recurrence limits; omitted means unlimited. */
|
|
87
|
+
recurrence?: CommissionPlanComponentRecurrence;
|
|
88
|
+
/**
|
|
89
|
+
* For basis `custom`: the key into the earning event's `customBases`
|
|
90
|
+
* JSON map (`basisKey → cents`) that supplies the base amount.
|
|
91
|
+
*/
|
|
92
|
+
customBasisKey?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Everything needed to reproduce a Commission's `amountCents` from first
|
|
96
|
+
* principles. Persisted as a JSON string on every Commission so amounts stay
|
|
97
|
+
* auditable even after plans are superseded.
|
|
98
|
+
*/
|
|
99
|
+
export interface CommissionCalculationTrace {
|
|
100
|
+
planKey: string;
|
|
101
|
+
planVersion: number;
|
|
102
|
+
componentKey: string;
|
|
103
|
+
basis: CommissionBasis;
|
|
104
|
+
/** Base amount the rate was applied to, in integer cents. */
|
|
105
|
+
baseAmountCents: number;
|
|
106
|
+
/** Rate applied (0–1). Recorded as `0` for `fixed`-basis components. */
|
|
107
|
+
rate: number;
|
|
108
|
+
/** Split share applied (0–1; `1` for unsplit commissions). */
|
|
109
|
+
shareFraction: number;
|
|
110
|
+
/** Zero-based occurrence index within the component's recurrence. */
|
|
111
|
+
occurrenceIndex: number;
|
|
112
|
+
/** Id of the {@link EarningEvent} evidence row. */
|
|
113
|
+
earningEventId: string;
|
|
114
|
+
/** Rounding contract used by `roundCents()`. */
|
|
115
|
+
roundingMode: 'half_away_from_zero';
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Computed (never stored) per-earner, per-currency balance snapshot.
|
|
119
|
+
* All figures in integer cents.
|
|
120
|
+
*/
|
|
121
|
+
export interface EarnerBalance {
|
|
122
|
+
earnerId: string;
|
|
123
|
+
currency: string;
|
|
124
|
+
/** Σ unsettled `payable` commissions. */
|
|
125
|
+
payableCents: number;
|
|
126
|
+
/** Σ `pending` commissions (still clearing). */
|
|
127
|
+
pendingCents: number;
|
|
128
|
+
/** Σ `earned` commissions (cleared, awaiting approval). */
|
|
129
|
+
earnedCents: number;
|
|
130
|
+
/** Σ `approved` commissions (awaiting payable release). */
|
|
131
|
+
approvedCents: number;
|
|
132
|
+
/**
|
|
133
|
+
* Σ unsettled adjustments whose parent commission is
|
|
134
|
+
* earned/approved/payable/paid (signed — clawbacks are negative).
|
|
135
|
+
*/
|
|
136
|
+
unsettledAdjustmentCents: number;
|
|
137
|
+
/** `payableCents + unsettledAdjustmentCents`. May be negative. */
|
|
138
|
+
netPayableCents: number;
|
|
139
|
+
}
|
|
140
|
+
/** Options for constructing an {@link Earner}. */
|
|
141
|
+
export interface EarnerOptions extends SmrtObjectOptions {
|
|
142
|
+
tenantId?: string | null;
|
|
143
|
+
profileId?: string;
|
|
144
|
+
displayName?: string;
|
|
145
|
+
status?: EarnerStatus;
|
|
146
|
+
payoutMethod?: PayoutMethod;
|
|
147
|
+
payoutThresholdCents?: number;
|
|
148
|
+
payoutScheduleKey?: string;
|
|
149
|
+
currency?: string;
|
|
150
|
+
metadata?: string;
|
|
151
|
+
}
|
|
152
|
+
/** Options for constructing a {@link CommissionPlan}. */
|
|
153
|
+
export interface CommissionPlanOptions extends SmrtObjectOptions {
|
|
154
|
+
tenantId?: string | null;
|
|
155
|
+
planKey?: string;
|
|
156
|
+
version?: number;
|
|
157
|
+
name?: string;
|
|
158
|
+
description?: string;
|
|
159
|
+
status?: CommissionPlanStatus;
|
|
160
|
+
effectiveFrom?: Date | string | number | null;
|
|
161
|
+
currency?: string;
|
|
162
|
+
components?: string;
|
|
163
|
+
metadata?: string;
|
|
164
|
+
}
|
|
165
|
+
/** Options for constructing an {@link EarningEvent}. */
|
|
166
|
+
export interface EarningEventOptions extends SmrtObjectOptions {
|
|
167
|
+
tenantId?: string | null;
|
|
168
|
+
eventKind?: string;
|
|
169
|
+
occurredAt?: Date | string | number;
|
|
170
|
+
sourceKind?: string;
|
|
171
|
+
sourceId?: string;
|
|
172
|
+
grossAmountCents?: number;
|
|
173
|
+
netAmountCents?: number | null;
|
|
174
|
+
marginCents?: number | null;
|
|
175
|
+
currency?: string;
|
|
176
|
+
customBases?: string;
|
|
177
|
+
dedupeKey?: string;
|
|
178
|
+
metadata?: string;
|
|
179
|
+
}
|
|
180
|
+
/** Options for constructing a {@link Commission}. */
|
|
181
|
+
export interface CommissionOptions extends SmrtObjectOptions {
|
|
182
|
+
tenantId?: string | null;
|
|
183
|
+
earnerId?: string;
|
|
184
|
+
earningEventId?: string;
|
|
185
|
+
planKey?: string;
|
|
186
|
+
planVersion?: number;
|
|
187
|
+
componentKey?: string;
|
|
188
|
+
termsSnapshotKind?: string;
|
|
189
|
+
termsSnapshotId?: string;
|
|
190
|
+
basis?: CommissionBasis;
|
|
191
|
+
baseAmountCents?: number;
|
|
192
|
+
rate?: number;
|
|
193
|
+
shareFraction?: number;
|
|
194
|
+
splitGroupId?: string;
|
|
195
|
+
amountCents?: number;
|
|
196
|
+
currency?: string;
|
|
197
|
+
status?: CommissionStatus;
|
|
198
|
+
clearingEndsAt?: Date | string | number | null;
|
|
199
|
+
earnedAt?: Date | string | number | null;
|
|
200
|
+
approvedAt?: Date | string | number | null;
|
|
201
|
+
payableAt?: Date | string | number | null;
|
|
202
|
+
paidAt?: Date | string | number | null;
|
|
203
|
+
payoutId?: string;
|
|
204
|
+
sourceKind?: string;
|
|
205
|
+
sourceId?: string;
|
|
206
|
+
calculationTrace?: string;
|
|
207
|
+
dedupeKey?: string;
|
|
208
|
+
metadata?: string;
|
|
209
|
+
}
|
|
210
|
+
/** Options for constructing a {@link CommissionAdjustment}. */
|
|
211
|
+
export interface CommissionAdjustmentOptions extends SmrtObjectOptions {
|
|
212
|
+
tenantId?: string | null;
|
|
213
|
+
commissionId?: string;
|
|
214
|
+
earnerId?: string;
|
|
215
|
+
adjustmentKind?: CommissionAdjustmentKind;
|
|
216
|
+
amountCents?: number;
|
|
217
|
+
currency?: string;
|
|
218
|
+
reason?: string;
|
|
219
|
+
createdByProfileId?: string;
|
|
220
|
+
payoutId?: string;
|
|
221
|
+
metadata?: string;
|
|
222
|
+
}
|
|
223
|
+
/** Options for constructing a {@link CommissionPayout}. */
|
|
224
|
+
export interface CommissionPayoutOptions extends SmrtObjectOptions {
|
|
225
|
+
tenantId?: string | null;
|
|
226
|
+
earnerId?: string;
|
|
227
|
+
periodStart?: Date | string | number | null;
|
|
228
|
+
periodEnd?: Date | string | number | null;
|
|
229
|
+
commissionTotalCents?: number;
|
|
230
|
+
adjustmentTotalCents?: number;
|
|
231
|
+
totalAmountCents?: number;
|
|
232
|
+
currency?: string;
|
|
233
|
+
payoutMethod?: PayoutMethod;
|
|
234
|
+
status?: CommissionPayoutStatus;
|
|
235
|
+
paymentReference?: string;
|
|
236
|
+
providerRef?: string;
|
|
237
|
+
paidAt?: Date | string | number | null;
|
|
238
|
+
invoiceId?: string;
|
|
239
|
+
notes?: string;
|
|
240
|
+
idempotencyKey?: string;
|
|
241
|
+
metadata?: string;
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/commissions/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAMlE,qDAAqD;AACrD,eAAO,MAAM,eAAe,6CAA8C,CAAC;AAC3E,MAAM,MAAM,YAAY,GA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IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commissions.d.ts","sourceRoot":"","sources":["../src/commissions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,wBAAwB,CAAC;AAEhC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import "./chunks/__smrt-register__-kWdT7LOt.js";
|
|
2
|
+
import { A as CommissionAdjustment, C as EARNING_EVENT_KINDS, D as CommissionCollection, E as CommissionPayout, O as Commission, S as EARNER_STATUSES, T as CommissionPayoutCollection, _ as COMMISSION_ADJUSTMENT_KINDS, a as amountToCents, b as COMMISSION_PLAN_STATUSES, c as roundCents, d as EarnerCollection, f as Earner, g as ADJUSTMENT_SETTLEABLE_COMMISSION_STATUSES, h as validateCommissionPlanComponents, i as CommissionBalanceService, k as CommissionAdjustmentCollection, l as EarningEventCollection, m as CommissionPlan, n as CommissionPayoutService, o as calculateCommissionAmountCents, p as CommissionPlanCollection, r as CommissionCalculationService, s as centsToAmount, t as CommissionSettlementService, u as EarningEvent, v as COMMISSION_BASES, w as PAYOUT_METHODS, x as COMMISSION_STATUSES, y as COMMISSION_PAYOUT_STATUSES } from "./chunks/commissions-BCxqOKVM.js";
|
|
3
|
+
export { ADJUSTMENT_SETTLEABLE_COMMISSION_STATUSES, COMMISSION_ADJUSTMENT_KINDS, COMMISSION_BASES, COMMISSION_PAYOUT_STATUSES, COMMISSION_PLAN_STATUSES, COMMISSION_STATUSES, Commission, CommissionAdjustment, CommissionAdjustmentCollection, CommissionBalanceService, CommissionCalculationService, CommissionCollection, CommissionPayout, CommissionPayoutCollection, CommissionPayoutService, CommissionPlan, CommissionPlanCollection, CommissionSettlementService, EARNER_STATUSES, EARNING_EVENT_KINDS, Earner, EarnerCollection, EarningEvent, EarningEventCollection, PAYOUT_METHODS, amountToCents, calculateCommissionAmountCents, centsToAmount, roundCents, validateCommissionPlanComponents };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { Lead } from '../models/Lead.js';
|
|
3
|
+
import { Opportunity } from '../models/Opportunity.js';
|
|
4
|
+
import { SalesActivity } from '../models/SalesActivity.js';
|
|
5
|
+
import { LeadStatus, MergeLeadsParams, MergeLeadsResult, QualifyLeadParams } from '../types.js';
|
|
6
|
+
export declare class LeadCollection extends SmrtCollection<Lead> {
|
|
7
|
+
static readonly _itemClass: typeof Lead;
|
|
8
|
+
private opportunityCollectionPromise;
|
|
9
|
+
private pipelineCollectionPromise;
|
|
10
|
+
private activityCollectionPromise;
|
|
11
|
+
/** Sibling opportunity collection sharing this collection's DB connection. */
|
|
12
|
+
private getOpportunityCollection;
|
|
13
|
+
/** Sibling pipeline collection sharing this collection's DB connection. */
|
|
14
|
+
private getPipelineCollection;
|
|
15
|
+
/** Sibling activity collection sharing this collection's DB connection. */
|
|
16
|
+
private getActivityCollection;
|
|
17
|
+
/** Leads in a given lifecycle status, newest first. */
|
|
18
|
+
findByStatus(status: LeadStatus): Promise<Lead[]>;
|
|
19
|
+
/** Leads owned by a given sales rep, newest first. */
|
|
20
|
+
findByOwner(ownerRepId: string): Promise<Lead[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Qualify a lead into an Opportunity.
|
|
23
|
+
*
|
|
24
|
+
* Transitions the lead to `qualified` (stamping `qualifiedAt` once) and
|
|
25
|
+
* creates an Opportunity at the FIRST stage of the target pipeline —
|
|
26
|
+
* `pipelineId` when given, otherwise the seeded default pipeline
|
|
27
|
+
* (`ensureDefaultPipeline()`). The opportunity adopts the first stage's
|
|
28
|
+
* probability, copies the lead's `sourceKind`/`sourceId` for reporting,
|
|
29
|
+
* and defaults its name/owner from the lead. A `qualification`
|
|
30
|
+
* SalesActivity is written on BOTH the lead and the opportunity.
|
|
31
|
+
*
|
|
32
|
+
* IDEMPOTENT: when the lead is already `qualified` and an opportunity
|
|
33
|
+
* exists for it, that opportunity is returned unchanged (no new rows, no
|
|
34
|
+
* new activities). A qualified lead with no opportunity (interrupted
|
|
35
|
+
* earlier run) is healed by creating the missing opportunity.
|
|
36
|
+
*
|
|
37
|
+
* Illegal source statuses are rejected by the lead's save-time transition
|
|
38
|
+
* guard (`disqualified`/`merged` leads cannot be qualified).
|
|
39
|
+
*
|
|
40
|
+
* @returns The (existing or newly created) opportunity
|
|
41
|
+
*/
|
|
42
|
+
qualify(params: QualifyLeadParams): Promise<Opportunity>;
|
|
43
|
+
/**
|
|
44
|
+
* Audited duplicate merge: fold the `loserId` lead into the `winnerId`
|
|
45
|
+
* lead.
|
|
46
|
+
*
|
|
47
|
+
* Validations: the ids must differ, both leads must exist, the loser must
|
|
48
|
+
* not already be merged, the winner must not itself be merged (merge into
|
|
49
|
+
* the chain head instead), and the merge must not create a
|
|
50
|
+
* `mergedIntoId` cycle.
|
|
51
|
+
*
|
|
52
|
+
* Effects:
|
|
53
|
+
* - EMPTY winner contact fields (`contactName`/`email`/`phone`/
|
|
54
|
+
* `organizationName`) are filled from the loser; non-empty winner data
|
|
55
|
+
* is never overwritten;
|
|
56
|
+
* - the loser's acquisition context is appended into the winner's under a
|
|
57
|
+
* `mergedSources` array (both histories preserved verbatim);
|
|
58
|
+
* - the loser becomes terminal: `status: 'merged'` +
|
|
59
|
+
* `mergedIntoId: winnerId`;
|
|
60
|
+
* - a `merge` SalesActivity is written on BOTH leads, each carrying a full
|
|
61
|
+
* pre-merge loser snapshot in metadata;
|
|
62
|
+
* - the loser's existing activities STAY attached to the loser (history
|
|
63
|
+
* preserved in place) — read the combined trail via
|
|
64
|
+
* {@link activitiesIncludingMerged}.
|
|
65
|
+
*/
|
|
66
|
+
mergeLeads(params: MergeLeadsParams): Promise<MergeLeadsResult>;
|
|
67
|
+
/**
|
|
68
|
+
* The lead's activity trail INCLUDING the trails of every lead merged into
|
|
69
|
+
* it, transitively (losers keep their own activities; this read
|
|
70
|
+
* re-assembles the full history across `mergedIntoId` chains).
|
|
71
|
+
*
|
|
72
|
+
* Traversal is breadth-first over merge children with a visited-set guard,
|
|
73
|
+
* so malformed cyclic data cannot loop. Results are in chronological
|
|
74
|
+
* order.
|
|
75
|
+
*/
|
|
76
|
+
activitiesIncludingMerged(leadId: string): Promise<SalesActivity[]>;
|
|
77
|
+
}
|
|
78
|
+
export default LeadCollection;
|
|
79
|
+
//# sourceMappingURL=LeadCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LeadCollection.d.ts","sourceRoot":"","sources":["../../../src/crm/collections/LeadCollection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAyBrB,qBAAa,cAAe,SAAQ,cAAc,CAAC,IAAI,CAAC;IACtD,MAAM,CAAC,QAAQ,CAAC,UAAU,cAAQ;IAElC,OAAO,CAAC,4BAA4B,CAC7B;IACP,OAAO,CAAC,yBAAyB,CAC1B;IACP,OAAO,CAAC,yBAAyB,CAC1B;IAEP,8EAA8E;YAChE,wBAAwB;IAStC,2EAA2E;YAC7D,qBAAqB;IASnC,2EAA2E;YAC7D,qBAAqB;IASnC,uDAAuD;IACjD,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAOvD,sDAAsD;IAChD,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAOtD;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAqG9D;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA+GrE;;;;;;;;OAQG;IACG,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAuB1E;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { Opportunity } from '../models/Opportunity.js';
|
|
3
|
+
import { MoveToStageParams } from '../types.js';
|
|
4
|
+
export declare class OpportunityCollection extends SmrtCollection<Opportunity> {
|
|
5
|
+
static readonly _itemClass: typeof Opportunity;
|
|
6
|
+
private stageCollectionPromise;
|
|
7
|
+
private activityCollectionPromise;
|
|
8
|
+
/** Sibling stage collection sharing this collection's DB connection. */
|
|
9
|
+
private getStageCollection;
|
|
10
|
+
/** Sibling activity collection sharing this collection's DB connection. */
|
|
11
|
+
private getActivityCollection;
|
|
12
|
+
/**
|
|
13
|
+
* Opportunities originating from a given lead, oldest first (the first row
|
|
14
|
+
* is the one `LeadCollection.qualify()` treats as canonical).
|
|
15
|
+
*/
|
|
16
|
+
findByLead(leadId: string): Promise<Opportunity[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Open (still in play) opportunities, optionally narrowed to one pipeline.
|
|
19
|
+
*/
|
|
20
|
+
findOpen(pipelineId?: string): Promise<Opportunity[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Move an opportunity to another stage of ITS pipeline, with the full
|
|
23
|
+
* consequence set:
|
|
24
|
+
*
|
|
25
|
+
* - validates the target stage belongs to the opportunity's pipeline
|
|
26
|
+
* (an opportunity created without a pipeline adopts the stage's);
|
|
27
|
+
* - adopts the stage's default `probability` unless
|
|
28
|
+
* `probabilityOverride` is given;
|
|
29
|
+
* - terminal stages close the deal: `isWon` sets `status: 'won'` +
|
|
30
|
+
* `wonAt`; `isLost` sets `status: 'lost'` + `lostAt` (record the loss
|
|
31
|
+
* reason via `outcomeReason`);
|
|
32
|
+
* - writes a `stage_change` SalesActivity carrying from/to detail.
|
|
33
|
+
*
|
|
34
|
+
* Moves after a terminal status are rejected — a closed deal's history is
|
|
35
|
+
* settled; reopening is not supported (create a new opportunity instead).
|
|
36
|
+
*
|
|
37
|
+
* @returns The updated opportunity
|
|
38
|
+
*/
|
|
39
|
+
moveToStage(params: MoveToStageParams): Promise<Opportunity>;
|
|
40
|
+
}
|
|
41
|
+
export default OpportunityCollection;
|
|
42
|
+
//# sourceMappingURL=OpportunityCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpportunityCollection.d.ts","sourceRoot":"","sources":["../../../src/crm/collections/OpportunityCollection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrD,qBAAa,qBAAsB,SAAQ,cAAc,CAAC,WAAW,CAAC;IACpE,MAAM,CAAC,QAAQ,CAAC,UAAU,qBAAe;IAEzC,OAAO,CAAC,sBAAsB,CACvB;IACP,OAAO,CAAC,yBAAyB,CAC1B;IAEP,wEAAwE;YAC1D,kBAAkB;IAShC,2EAA2E;YAC7D,qBAAqB;IASnC;;;OAGG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAOxD;;OAEG;IACG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAO3D;;;;;;;;;;;;;;;;;OAiBG;IACG,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;CA2EnE;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { OpportunityConversion } from '../models/OpportunityConversion.js';
|
|
3
|
+
import { RecordConversionParams, RecordConversionResult } from '../types.js';
|
|
4
|
+
export declare class OpportunityConversionCollection extends SmrtCollection<OpportunityConversion> {
|
|
5
|
+
static readonly _itemClass: typeof OpportunityConversion;
|
|
6
|
+
private opportunityCollectionPromise;
|
|
7
|
+
/** Sibling opportunity collection sharing this collection's DB connection. */
|
|
8
|
+
private getOpportunityCollection;
|
|
9
|
+
/** All conversion links recorded for one opportunity, oldest first. */
|
|
10
|
+
findByOpportunity(opportunityId: string): Promise<OpportunityConversion[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Record that a WON opportunity materialized into a downstream record,
|
|
13
|
+
* idempotently on the natural key `(opportunityId, targetKind, targetId)`.
|
|
14
|
+
*
|
|
15
|
+
* Preconditions: the opportunity must exist and its status must be `'won'`
|
|
16
|
+
* — conversions from open or lost deals are rejected with a clear error.
|
|
17
|
+
* CRM only records the link; creating the downstream record itself
|
|
18
|
+
* (client, project, contract, subscription, …) is the caller's job.
|
|
19
|
+
*
|
|
20
|
+
* @returns `{ conversion, created }` — `created: false` when the link
|
|
21
|
+
* already existed (the existing row is returned untouched)
|
|
22
|
+
*/
|
|
23
|
+
recordConversion(params: RecordConversionParams): Promise<RecordConversionResult>;
|
|
24
|
+
}
|
|
25
|
+
export default OpportunityConversionCollection;
|
|
26
|
+
//# sourceMappingURL=OpportunityConversionCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpportunityConversionCollection.d.ts","sourceRoot":"","sources":["../../../src/crm/collections/OpportunityConversionCollection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,qBAAa,+BAAgC,SAAQ,cAAc,CAAC,qBAAqB,CAAC;IACxF,MAAM,CAAC,QAAQ,CAAC,UAAU,+BAAyB;IAEnD,OAAO,CAAC,4BAA4B,CAC7B;IAEP,8EAA8E;YAChE,wBAAwB;IAStC,uEAAuE;IACjE,iBAAiB,CACrB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAOnC;;;;;;;;;;;OAWG;IACG,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,sBAAsB,CAAC;CAsCnC;AAED,eAAe,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { PipelineDefinition } from '../models/PipelineDefinition.js';
|
|
3
|
+
import { PipelineStage } from '../models/PipelineStage.js';
|
|
4
|
+
import { EnsureDefaultPipelineParams, EnsureDefaultPipelineResult } from '../types.js';
|
|
5
|
+
export declare class PipelineDefinitionCollection extends SmrtCollection<PipelineDefinition> {
|
|
6
|
+
static readonly _itemClass: typeof PipelineDefinition;
|
|
7
|
+
private stageCollectionPromise;
|
|
8
|
+
/** Sibling stage collection sharing this collection's DB connection. */
|
|
9
|
+
private getStageCollection;
|
|
10
|
+
/**
|
|
11
|
+
* Find one pipeline by its machine key (natural key within the tenant
|
|
12
|
+
* scope — ambient tenancy auto-filters the lookup).
|
|
13
|
+
*/
|
|
14
|
+
findByKey(key: string): Promise<PipelineDefinition | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Find the pipeline flagged `isDefault` (informational designation).
|
|
17
|
+
*/
|
|
18
|
+
findDefault(): Promise<PipelineDefinition | null>;
|
|
19
|
+
/**
|
|
20
|
+
* A pipeline's stages in board order (`sortOrder` ascending).
|
|
21
|
+
*/
|
|
22
|
+
getStages(pipelineId: string): Promise<PipelineStage[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Idempotently find-or-create the seeded default pipeline (key
|
|
25
|
+
* `'default'`, `isDefault: true`) and its 7 default stages:
|
|
26
|
+
* `new(0.1) → qualified(0.25) → discovery(0.4) → proposal(0.6) →
|
|
27
|
+
* negotiation(0.8) → closed_won(1.0, isWon) → closed_lost(0.0, isLost)`.
|
|
28
|
+
*
|
|
29
|
+
* Idempotency is per stage KEY: a second call creates nothing, and a
|
|
30
|
+
* partially-seeded pipeline (e.g. an interrupted first run) is healed by
|
|
31
|
+
* creating only the missing keys. Existing stages are never overwritten —
|
|
32
|
+
* renames, re-weights, reorders, and custom stages added via normal
|
|
33
|
+
* PipelineStage operations all survive re-runs.
|
|
34
|
+
*
|
|
35
|
+
* Tenancy: under an ambient `withTenant()` context the pipeline/stages
|
|
36
|
+
* auto-scope to that tenant; pass `tenantId` to seed for a specific tenant
|
|
37
|
+
* from a system/global context. Lookup is by natural key, so each tenant
|
|
38
|
+
* gets exactly one seeded default pipeline.
|
|
39
|
+
*
|
|
40
|
+
* @returns The pipeline plus ALL of its stages ordered by `sortOrder`
|
|
41
|
+
* (including any custom stages added since seeding)
|
|
42
|
+
*/
|
|
43
|
+
ensureDefaultPipeline(params?: EnsureDefaultPipelineParams): Promise<EnsureDefaultPipelineResult>;
|
|
44
|
+
}
|
|
45
|
+
export default PipelineDefinitionCollection;
|
|
46
|
+
//# sourceMappingURL=PipelineDefinitionCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PipelineDefinitionCollection.d.ts","sourceRoot":"","sources":["../../../src/crm/collections/PipelineDefinitionCollection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAGL,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EACjC,MAAM,aAAa,CAAC;AAWrB,qBAAa,4BAA6B,SAAQ,cAAc,CAAC,kBAAkB,CAAC;IAClF,MAAM,CAAC,QAAQ,CAAC,UAAU,4BAAsB;IAEhD,OAAO,CAAC,sBAAsB,CACvB;IAEP,wEAAwE;YAC1D,kBAAkB;IAShC;;;OAGG;IACG,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAKhE;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IASvD;;OAEG;IACG,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAK7D;;;;;;;;;;;;;;;;;;;OAmBG;IACG,qBAAqB,CACzB,MAAM,GAAE,2BAAgC,GACvC,OAAO,CAAC,2BAA2B,CAAC;CAmDxC;AAED,eAAe,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { PipelineStage } from '../models/PipelineStage.js';
|
|
3
|
+
export declare class PipelineStageCollection extends SmrtCollection<PipelineStage> {
|
|
4
|
+
static readonly _itemClass: typeof PipelineStage;
|
|
5
|
+
/**
|
|
6
|
+
* List a pipeline's stages in board order.
|
|
7
|
+
*
|
|
8
|
+
* @param pipelineId - Owning PipelineDefinition id
|
|
9
|
+
* @returns Stages ordered by `sortOrder` ascending
|
|
10
|
+
*/
|
|
11
|
+
findByPipeline(pipelineId: string): Promise<PipelineStage[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Find one stage by its natural key within a pipeline.
|
|
14
|
+
*
|
|
15
|
+
* @param pipelineId - Owning PipelineDefinition id
|
|
16
|
+
* @param key - Stage machine key (e.g. `'proposal'`)
|
|
17
|
+
* @returns The stage, or null when the key does not exist in the pipeline
|
|
18
|
+
*/
|
|
19
|
+
findByKey(pipelineId: string, key: string): Promise<PipelineStage | null>;
|
|
20
|
+
}
|
|
21
|
+
export default PipelineStageCollection;
|
|
22
|
+
//# sourceMappingURL=PipelineStageCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PipelineStageCollection.d.ts","sourceRoot":"","sources":["../../../src/crm/collections/PipelineStageCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,qBAAa,uBAAwB,SAAQ,cAAc,CAAC,aAAa,CAAC;IACxE,MAAM,CAAC,QAAQ,CAAC,UAAU,uBAAiB;IAE3C;;;;;OAKG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAOlE;;;;;;OAMG;IACG,SAAS,CACb,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;CAOjC;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { SalesActivity } from '../models/SalesActivity.js';
|
|
3
|
+
import { SalesActivitySubjectKind } from '../types.js';
|
|
4
|
+
export declare class SalesActivityCollection extends SmrtCollection<SalesActivity> {
|
|
5
|
+
static readonly _itemClass: typeof SalesActivity;
|
|
6
|
+
/**
|
|
7
|
+
* Full trail for one subject, oldest first (chronological reading order).
|
|
8
|
+
*
|
|
9
|
+
* @param subjectKind - `'lead'` or `'opportunity'`
|
|
10
|
+
* @param subjectId - Subject row id
|
|
11
|
+
*/
|
|
12
|
+
findBySubject(subjectKind: SalesActivitySubjectKind, subjectId: string): Promise<SalesActivity[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Open next actions for one subject: activities with a due date
|
|
15
|
+
* (`dueAt` set) that have not been completed (`completedAt` null),
|
|
16
|
+
* soonest due first.
|
|
17
|
+
*
|
|
18
|
+
* @param subjectKind - `'lead'` or `'opportunity'`
|
|
19
|
+
* @param subjectId - Subject row id
|
|
20
|
+
*/
|
|
21
|
+
findOpenTasks(subjectKind: SalesActivitySubjectKind, subjectId: string): Promise<SalesActivity[]>;
|
|
22
|
+
}
|
|
23
|
+
export default SalesActivityCollection;
|
|
24
|
+
//# sourceMappingURL=SalesActivityCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SalesActivityCollection.d.ts","sourceRoot":"","sources":["../../../src/crm/collections/SalesActivityCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE5D,qBAAa,uBAAwB,SAAQ,cAAc,CAAC,aAAa,CAAC;IACxE,MAAM,CAAC,QAAQ,CAAC,UAAU,uBAAiB;IAE3C;;;;;OAKG;IACG,aAAa,CACjB,WAAW,EAAE,wBAAwB,EACrC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,EAAE,CAAC;IAO3B;;;;;;;OAOG;IACG,aAAa,CACjB,WAAW,EAAE,wBAAwB,EACrC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,EAAE,CAAC;CAW5B;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SmrtCollection } from '@happyvertical/smrt-core';
|
|
2
|
+
import { SalesRepresentative } from '../models/SalesRepresentative.js';
|
|
3
|
+
export declare class SalesRepresentativeCollection extends SmrtCollection<SalesRepresentative> {
|
|
4
|
+
static readonly _itemClass: typeof SalesRepresentative;
|
|
5
|
+
/**
|
|
6
|
+
* Find rep roles held by a given profile (a profile may hold the role in
|
|
7
|
+
* several tenants/contexts).
|
|
8
|
+
*
|
|
9
|
+
* @param profileId - smrt-profiles Profile id
|
|
10
|
+
* @returns Reps for that profile, newest first
|
|
11
|
+
*/
|
|
12
|
+
findByProfile(profileId: string): Promise<SalesRepresentative[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Find all active reps (eligible for new lead/opportunity assignment).
|
|
15
|
+
*/
|
|
16
|
+
findActive(): Promise<SalesRepresentative[]>;
|
|
17
|
+
}
|
|
18
|
+
export default SalesRepresentativeCollection;
|
|
19
|
+
//# sourceMappingURL=SalesRepresentativeCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SalesRepresentativeCollection.d.ts","sourceRoot":"","sources":["../../../src/crm/collections/SalesRepresentativeCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,qBAAa,6BAA8B,SAAQ,cAAc,CAAC,mBAAmB,CAAC;IACpF,MAAM,CAAC,QAAQ,CAAC,UAAU,6BAAuB;IAEjD;;;;;;OAMG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAOtE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;CAMnD;AAED,eAAe,6BAA6B,CAAC"}
|