@happyvertical/smrt-sales 0.40.14 → 0.40.15

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/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # @happyvertical/smrt-sales
2
+
3
+ Provider-neutral sales operations for s-m-r-t: agreement execution, CRM, referral
4
+ intake and attribution, a neutral commissions core, and reusable Svelte
5
+ surfaces. It is one installable package with subpaths that keep consumers scoped
6
+ to the modules they use.
7
+
8
+ `@happyvertical/smrt-affiliates` is a deprecated compatibility shim over the
9
+ commissions module. New applications should import this package directly.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pnpm add @happyvertical/smrt-sales
15
+ ```
16
+
17
+ Add `svelte` when consuming the optional UI export.
18
+
19
+ ## Modules
20
+
21
+ | Entry point | Responsibility |
22
+ | --- | --- |
23
+ | `@happyvertical/smrt-sales/agreements` | Verified e-signature execution and immutable evidence |
24
+ | `@happyvertical/smrt-sales/crm` | Leads, pipelines, opportunities, activities, conversions |
25
+ | `@happyvertical/smrt-sales/referrals` | Referrers, links, attribution, qualification, agreements |
26
+ | `@happyvertical/smrt-sales/commissions` | Earners, plans, earning events, commissions, payouts |
27
+ | `@happyvertical/smrt-sales/svelte` | CRM, referrer, commission, and operator surfaces |
28
+
29
+ The root export re-exports all TypeScript modules for convenience.
30
+
31
+ ## Quick start: commission terms
32
+
33
+ ```ts
34
+ import {
35
+ CommissionPlanCollection,
36
+ EarnerCollection,
37
+ } from '@happyvertical/smrt-sales/commissions';
38
+
39
+ const db = 'sales.db';
40
+ const earners = await EarnerCollection.create({ db });
41
+ const plans = await CommissionPlanCollection.create({ db });
42
+
43
+ const earner = await earners.create({
44
+ tenantId: 'tenant-1',
45
+ profileId: 'profile-42',
46
+ displayName: 'North Region Partner',
47
+ status: 'active',
48
+ currency: 'CAD',
49
+ });
50
+
51
+ const plan = await plans.create({
52
+ tenantId: 'tenant-1',
53
+ planKey: 'referral-standard',
54
+ name: 'Standard referral plan',
55
+ currency: 'CAD',
56
+ });
57
+ plan.setComponents([
58
+ {
59
+ key: 'collected-revenue',
60
+ trigger: 'collected_revenue',
61
+ basis: 'gross',
62
+ rate: 0.1,
63
+ recurrence: { kind: 'one_time' },
64
+ },
65
+ ]);
66
+ plan.activate();
67
+ await plan.save();
68
+
69
+ console.log(earner.id, plan.getComponents());
70
+ ```
71
+
72
+ All money fields use integer cents. Rates and probability-like values use
73
+ decimals from `0` to `1`; rounding occurs through the exported money helpers.
74
+
75
+ ## Core model
76
+
77
+ - **Roles are separate from money.** `SalesRepresentative` and `Referrer` are
78
+ distinct roles; both point to one neutral `Earner` payout identity.
79
+ - **Terms are versioned rows.** Activated commission plans, attribution
80
+ policies, and referral agreements are amended with new versions.
81
+ - **Evidence is immutable.** Earning events, executed agreements, referral
82
+ touches, and adjustments are append-only or guarded after activation.
83
+ - **Retries are explicit.** Stable dedupe/idempotency keys prevent duplicated
84
+ earning, click, adjustment, agreement, and payout operations.
85
+ - **Writes use services where required.** Payout transitions, adjustments,
86
+ agreement execution, and attribution have service-owned invariants that raw
87
+ generated CRUD must not bypass.
88
+
89
+ ## Agreement boundary
90
+
91
+ The agreements module accepts the provider-neutral
92
+ `@happyvertical/signatures` contract plus an `AssetRuntimeLike`. Provider
93
+ credentials remain in the injected SDK adapter and secret store. Executed
94
+ agreements freeze the exact source, signed document, audit trail, hashes, and
95
+ signer evidence; amendments create new records.
96
+
97
+ ## Tenancy and cross-package references
98
+
99
+ Most business models are optionally tenant scoped so intentional global
100
+ operator rows remain possible. Execution evidence and private operation fences
101
+ are required-tenant records. Profile, invoice, and asset references use
102
+ cross-package string references rather than circular runtime dependencies.
103
+
104
+ ## Migration from affiliates
105
+
106
+ See [`smrt-affiliates`](../affiliates/README.md) and its migration guide for the
107
+ legacy mapping: `Partner` becomes `Earner`, and `Payout` becomes
108
+ `CommissionPayout`. The compatibility package owns no duplicate models or
109
+ tables.
110
+
111
+ ## Development
112
+
113
+ ```bash
114
+ pnpm --filter @happyvertical/smrt-sales test
115
+ pnpm --filter @happyvertical/smrt-sales typecheck
116
+ pnpm --filter @happyvertical/smrt-sales test:postgres
117
+ pnpm --filter @happyvertical/smrt-sales build
118
+ ```
119
+
120
+ See [`AGENTS.md`](./AGENTS.md) for lifecycle, evidence, concurrency, and payout
121
+ invariants.
@@ -1,3 +1,3 @@
1
- import "./chunks/__smrt-register__-D5vDbBna.js";
1
+ import "./chunks/__smrt-register__-B8_SpkS9.js";
2
2
  import { a as AgreementExecutionEvent, c as AGREEMENT_EXECUTION_STATUSES, d as sanitizeSignerIntent, i as AgreementExecutionEventCollection, l as coerceAgreementDate, n as ExecutedAgreementCollection, o as AgreementExecutionCollection, r as ExecutedAgreement, s as AgreementExecution, t as AgreementExecutionService, u as sanitizeSignerEvidence } from "./chunks/agreements-DbzW1Pcq.js";
3
3
  export { AGREEMENT_EXECUTION_STATUSES, AgreementExecution, AgreementExecutionCollection, AgreementExecutionEvent, AgreementExecutionEventCollection, AgreementExecutionService, ExecutedAgreement, ExecutedAgreementCollection, coerceAgreementDate, sanitizeSignerEvidence, sanitizeSignerIntent };