@happyvertical/smrt-sales 0.60.11 → 0.60.13

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 (39) hide show
  1. package/AGENTS.md +1 -0
  2. package/README.md +10 -0
  3. package/agents/referrals.md +28 -1
  4. package/dist/agreements.js +1 -1
  5. package/dist/chunks/{__smrt-register__-a4KFA58F.js → __smrt-register__-BLLZk-ni.js} +2 -2
  6. package/dist/chunks/{__smrt-register__-a4KFA58F.js.map → __smrt-register__-BLLZk-ni.js.map} +1 -1
  7. package/dist/chunks/{referrals-DQaEehr8.js → referrals-STQ8kdIv.js} +674 -174
  8. package/dist/chunks/referrals-STQ8kdIv.js.map +1 -0
  9. package/dist/commissions.js +1 -1
  10. package/dist/crm.js +1 -1
  11. package/dist/index.js +3 -3
  12. package/dist/manifest.json +530 -2
  13. package/dist/referrals/collections/AttributionExceptionCollection.d.ts +1 -1
  14. package/dist/referrals/collections/AttributionExceptionCollection.d.ts.map +1 -1
  15. package/dist/referrals/collections/ReferrerIdentifierCollection.d.ts +20 -0
  16. package/dist/referrals/collections/ReferrerIdentifierCollection.d.ts.map +1 -0
  17. package/dist/referrals/index.d.ts +3 -0
  18. package/dist/referrals/index.d.ts.map +1 -1
  19. package/dist/referrals/models/AttributionException.d.ts +4 -3
  20. package/dist/referrals/models/AttributionException.d.ts.map +1 -1
  21. package/dist/referrals/models/ReferralTouch.d.ts +4 -3
  22. package/dist/referrals/models/ReferralTouch.d.ts.map +1 -1
  23. package/dist/referrals/models/ReferrerIdentifier.d.ts +24 -0
  24. package/dist/referrals/models/ReferrerIdentifier.d.ts.map +1 -0
  25. package/dist/referrals/nomination-identity.d.ts +3 -0
  26. package/dist/referrals/nomination-identity.d.ts.map +1 -0
  27. package/dist/referrals/services/AttributionService.d.ts +5 -3
  28. package/dist/referrals/services/AttributionService.d.ts.map +1 -1
  29. package/dist/referrals/services/ReferralAgreementExecutionService.d.ts +1 -1
  30. package/dist/referrals/services/ReferralAgreementExecutionService.d.ts.map +1 -1
  31. package/dist/referrals/services/ReferralNominationResolver.d.ts +55 -0
  32. package/dist/referrals/services/ReferralNominationResolver.d.ts.map +1 -0
  33. package/dist/referrals/types.d.ts +21 -2
  34. package/dist/referrals/types.d.ts.map +1 -1
  35. package/dist/referrals.js +3 -3
  36. package/dist/smrt-knowledge.json +285 -11
  37. package/dist/smrt-knowledge.okf.md +6 -2
  38. package/package.json +8 -8
  39. package/dist/chunks/referrals-DQaEehr8.js.map +0 -1
package/AGENTS.md CHANGED
@@ -70,6 +70,7 @@ Business/domain models are generally `@TenantScoped({ mode: 'optional' })` with
70
70
  - **Agreement freeze scope**: activating a ReferralAgreement requires and freezes its execution/evidence refs along with its commercial terms. `effectiveTo` remains writable for explicit end-dating; signed bytes, hashes, signer evidence, and audit trail exist only on immutable ExecutedAgreement/Asset records.
71
71
  - **Circular FK pair by design**: `Referral.snapshotId ↔ ReferralTermSnapshot.referralId`. Fine on SQLite (and no cross-table DDL constraints are emitted for these string FKs); keep an eye on strict-DDL environments.
72
72
  - **Attribution resolution is single-writer per (target, program)**: `resolve()` is idempotent against PERSISTED state, but two workers resolving the same target concurrently can both pass the existence check and create duplicate credit — the collection layer has no cross-row transaction (the same stance as payout batching, which relies on disjoint scopes for concurrency). Run intake resolution serially per target (it naturally is, in a request handler); duplicates are visible in the portal and correctable via `override()`.
73
+ - **Nomination matches stay in one tenant lane**: register verified aliases through `ReferrerIdentifierCollection.register()`. Unresolved nominations go into the exception queue when the target is known. Bind the resolver to the intake or attribution executor and serialize qualification per target and program.
73
74
  - **recordClick inside your transaction participates, never nests**: a nested adapter `transaction()` takes an independent pooled connection (happyvertical/sdk#1108) — it deadlocks undetectably on locks the caller's transaction holds (PostgreSQL sees a promise-wait, not a lock-wait) and refuses caller-created uncommitted links as `unknown_code`. Pass the caller's transaction database as `RecordClickInput.transaction` or bind the collection to it (`{ db: tx, _reuseInitializedDb: true, _deferRuntimeInitialization: true }` — detected and honored automatically); a pool-level database passed as `transaction` is refused with typed reason `invalid_transaction`. Participating results are bound to the caller's transaction — carry ids across the commit boundary; the pool-bound default still self-transacts and rehydrates after commit.
74
75
  - **Click retries reuse one key**: pass the exact same non-empty, well-formed-Unicode `recordClick.idempotencyKey` (maximum 256 UTF-8 bytes) on transport/database retry. Omitting it remains source-compatible but creates and returns a one-shot UUID; it cannot deduplicate a later independent invocation. `maxEvidenceBytes` guards creation; changing it cannot turn an already-committed exact replay into failure. Replay validation is against the immutable operation/touch snapshot, not mutable current link fields: later link edits preserve exact replay, the result link is current, and the touch evidence is the original snapshot. The private optional-tenant `ReferralClickOperation` table is the serialization fence and must be included in schema migration. Never pre-bound caller evidence: Sales owns the authoritative final-envelope byte check.
75
76
  - **`ObjectRegistry.getConfig(X)` needs the class module imported** (decorator side effects) — manifest-only registration doesn't carry api/mcp/conflictColumns; tests asserting surface configs need a side-effect import of the module barrel.
package/README.md CHANGED
@@ -194,6 +194,16 @@ to use an empty descriptor. Unknown/malformed descriptors and extra fields
194
194
  agreement execution, and attribution have service-owned invariants that raw
195
195
  generated CRUD must not bypass.
196
196
 
197
+ ## Referrer nominations
198
+
199
+ Register known aliases with `ReferrerIdentifierCollection.register()`. A host
200
+ can record a matched nomination at intake using `ReferralNominationResolver`
201
+ and later resolve it under the referral program's active policy. An ambiguous
202
+ or unknown nomination opens an operator review with the original input and
203
+ policy version. Run the normal manifest migration to add
204
+ `referrer_identifiers`. See [referral behavior](agents/referrals.md) for matching
205
+ rules, replay, and tenant boundaries.
206
+
197
207
  ## Lead intake and lifecycle
198
208
 
199
209
  `LeadWorkflowService` is the tenant-safe, application-facing seam for generic
@@ -6,13 +6,40 @@ money), and the Gotchas that apply before editing anything live in
6
6
  [../AGENTS.md](../AGENTS.md) — read that first.
7
7
 
8
8
  - **Referrer**: role model (`profileId`, `earnerId`, `status`).
9
+ - **ReferrerIdentifier**: append-only alias per tenant, kind, and normalized value. Optional program limits where it matches. Disable an obsolete alias to preserve its audit history and reservation. Register through `ReferrerIdentifierCollection.register()`, which derives the normalized value, checks same-lane ownership, and returns the existing active alias when the owner and program match.
9
10
  - **ReferralProgram**: program defaults — default commission plan key, default attribution policy key, eligibility defaults.
10
11
  - **AttributionPolicy**: versioned `(tenant_id, policy_key, version)` policy (per-tenant keys) — attribution `windowDays`, credit mode (`first_touch|last_touch|assigned|split`), split shares, self-referral/existing-client eligibility, eligible services/campaigns/regions, conflict behavior. Immutable once active; amendments bump `version`.
11
12
  - **ReferralLink**: shareable link/code per Referrer+Program. Codes are crypto-random and uniqueness-checked. `ReferralLinkCollection.recordClick()` transactionally creates one immutable touch plus one counter increment behind a caller replay key. Exact retries return the original touch; changed link/subject/time/evidence intent raises `ReferralClickReplayConflictError`. Replay comparison uses the immutable operation/touch snapshot, so later mutable link edits do not invalidate the retry; the result carries the current link and original touch evidence. The exact canonical persisted evidence JSON, after Sales overwrites `code`, `linkId`, and `targetUrl`, is bounded to 4096 UTF-8 bytes by default (`maxEvidenceBytes` customizes it). By default the click self-transacts and rehydrates results after commit; inside a caller's open transaction it must participate instead — pass the transaction database as `RecordClickInput.transaction`, or call it on a collection bound to that transaction, and the click joins the caller's atomicity with results bound to that transaction (#2083).
12
- - **ReferralTouch**: immutable attribution evidence (`click|code_entry|manual_assignment|partner_entry`) with subject hints and evidence JSON.
13
+ - **ReferralTouch**: immutable attribution evidence (`click|code_entry|manual_assignment|partner_entry|nomination`) with subject hints and evidence JSON.
13
14
  - **Referral**: the introduction — generic qualifying target (`targetKind`/`targetId`: lead, opportunity, client, project, subscription, …), resolved policy version, credit fraction (splits create sibling Referrals sharing `splitGroupId`), lifecycle `pending → attributed → qualified | disqualified | expired | under_review`.
14
15
  - **AttributionException**: conflict review queue. Conclusive policy resolves automatically; ambiguity creates an exception; overrides require a `resolutionReason` and are audited.
15
16
  - **ReferralAgreement**: versioned per-Referrer terms binding — pins `commissionPlanKey`/`planVersion`, effective dating, and an immutable `ExecutedAgreement` before activation. Amendments are fresh unsigned drafts and never inherit execution evidence.
16
17
  - **Plan compatibility**: qualification and requalification accept only v1 component plans. A pinned or latest-active v2 waterfall plan returns `unsupported_plan_engine` before snapshot/referral writes; existing snapshots remain valid and unchanged. Bind compatible component terms and retry to recover. Engine changes under a plan key never implicitly migrate referrals.
17
18
  - **ReferralTermSnapshot**: immutable at qualification — freezes agreement/plan/policy version refs plus the calculation inputs needed to reproduce every later earning.
18
19
  - **Services**: `ReferralAgreementExecutionService` binds generated Referral Agreement versions to the generic execution service and activates/supersedes them transactionally with future-effective amendment support; `AttributionService`, `ReferralQualificationService`, and `ReferralCommissionService` retain their existing attribution/qualification/earning responsibilities.
20
+
21
+
22
+ ## Prospect nominations
23
+
24
+ Hosts can call `ReferralNominationResolver.recordNomination()` during intake and
25
+ `resolve()` when an attribution target exists. Supply the same subject and
26
+ nomination inputs, using the original intake time when known. Exact registered
27
+ email, code, name, or handle and active program link codes take precedence over
28
+ display-name scoring. The fallback compares name-sized word spans and requires
29
+ a score of at least 0.85 and a lead of at least 0.12 over the runner-up.
30
+ Candidates must be active in the program's tenant lane.
31
+
32
+ A match records an immutable, deterministic touch with the original nomination
33
+ and match provenance. In `assigned` mode both manual assignments and matched
34
+ nominations can earn credit. Competing assignment-grade touches for distinct
35
+ referrers go to review. The program's current policy governs credit, and
36
+ qualification still requires the usual versioned agreement and plan.
37
+
38
+ Without a unique confident match, resolution creates one open
39
+ `nomination_unresolved` exception for the target and program with the original
40
+ inputs and policy pin. Candidate entries in this exception have an empty
41
+ `touchId`. Operators award credit using `AttributionService.resolveException()`.
42
+ They can then call `registerResolvedIdentifier()` to remember a verified alias
43
+ for a referrer who received credit. Run both operations in the caller's
44
+ transaction when registration and resolution must commit together. The host
45
+ authorizes both operations and serializes attribution per target and program.
@@ -1,3 +1,3 @@
1
- import "./chunks/__smrt-register__-a4KFA58F.js";
1
+ import "./chunks/__smrt-register__-BLLZk-ni.js";
2
2
  import { a as AgreementExecutionEvent, c as AgreementCollection, d as serializeAgreementParty, f as AGREEMENT_EXECUTION_STATUSES, g as sanitizeSignerIntent, h as sanitizeSignerEvidence, i as AgreementExecutionEventCollection, l as Agreement, m as coerceAgreementDate, n as ExecutedAgreementCollection, o as AgreementExecutionCollection, p as AGREEMENT_STATUSES, r as ExecutedAgreement, s as AgreementExecution, t as AgreementExecutionService, u as parseAgreementParty } from "./chunks/agreements-C8rxIVGB.js";
3
3
  export { AGREEMENT_EXECUTION_STATUSES, AGREEMENT_STATUSES, Agreement, AgreementCollection, AgreementExecution, AgreementExecutionCollection, AgreementExecutionEvent, AgreementExecutionEventCollection, AgreementExecutionService, ExecutedAgreement, ExecutedAgreementCollection, coerceAgreementDate, parseAgreementParty, sanitizeSignerEvidence, sanitizeSignerIntent, serializeAgreementParty };