@happyvertical/smrt-sales 0.57.34 → 0.57.35

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.
@@ -1,5 +1,5 @@
1
- import { W as CommissionCollection, i as CommissionCalculationService, v as CommissionPlanCollection } from "./commissions-nMBMa0DT.js";
2
- import { SmrtCollection, SmrtObject, crossPackageRef, field, foreignKey, smrt } from "@happyvertical/smrt-core";
1
+ import { D as CommissionPayout, G as Commission, O as Earner, W as CommissionCollection, i as CommissionCalculationService, v as CommissionPlanCollection } from "./commissions-DSVGf1ZX.js";
2
+ import { SmrtCollection, SmrtObject, SmrtRecipe, crossPackageRef, field, foreignKey, smrt } from "@happyvertical/smrt-core";
3
3
  import { TenantScoped, requireTenantId, tenantId } from "@happyvertical/smrt-tenancy";
4
4
  import { createHash, randomBytes, randomUUID } from "node:crypto";
5
5
  //#region src/referrals/models/AttributionException.ts
@@ -1111,10 +1111,6 @@ var Referral = class extends SmrtObject {
1111
1111
  policyKey = "";
1112
1112
  /** AttributionPolicy version resolved at attribution (0 until attributed). */
1113
1113
  policyVersion = 0;
1114
- /**
1115
- * Lifecycle status — see the module transition map. Mutate via the
1116
- * transition methods; the save-time guard rejects illegal edges.
1117
- */
1118
1114
  status = "pending";
1119
1115
  /**
1120
1116
  * Generic qualifying target: what the introduction became/points at —
@@ -1291,8 +1287,9 @@ var Referral = class extends SmrtObject {
1291
1287
  };
1292
1288
  __publicField$5(Referral, "__smrtPackage__", "@happyvertical/smrt-sales");
1293
1289
  __decorateClass$5([tenantId({ nullable: true })], Referral.prototype, "tenantId", 2);
1294
- __decorateClass$5([foreignKey("Referrer", { required: true })], Referral.prototype, "referrerId", 2);
1295
- __decorateClass$5([foreignKey("ReferralProgram", { required: true })], Referral.prototype, "programId", 2);
1290
+ __decorateClass$5([field({ description: "The affiliate who sent this person." }), foreignKey("Referrer", { required: true })], Referral.prototype, "referrerId", 2);
1291
+ __decorateClass$5([field({ description: "The program this referral counts towards." }), foreignKey("ReferralProgram", { required: true })], Referral.prototype, "programId", 2);
1292
+ __decorateClass$5([field({ description: "Whether the referral is waiting, has led to a sale or has lapsed." })], Referral.prototype, "status", 2);
1296
1293
  __decorateClass$5([foreignKey("ReferralTouch")], Referral.prototype, "primaryTouchId", 2);
1297
1294
  Referral = __decorateClass$5([TenantScoped({ mode: "optional" }), smrt({
1298
1295
  api: { include: [
@@ -2087,13 +2084,7 @@ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !==
2087
2084
  var ReferralProgram = class extends SmrtObject {
2088
2085
  tenantId = null;
2089
2086
  key = "";
2090
- /** Human-readable program name. */
2091
2087
  name = "";
2092
- /**
2093
- * Program lifecycle: `draft` (default) → `active` → `paused` /
2094
- * `archived`. Applications gate intake on `active`; this module records
2095
- * the status without enforcing transition edges.
2096
- */
2097
2088
  status = "draft";
2098
2089
  /**
2099
2090
  * Default commissions-plan key suggested to new ReferralAgreements.
@@ -2141,7 +2132,12 @@ var ReferralProgram = class extends SmrtObject {
2141
2132
  };
2142
2133
  __publicField$2(ReferralProgram, "__smrtPackage__", "@happyvertical/smrt-sales");
2143
2134
  __decorateClass$2([tenantId({ nullable: true })], ReferralProgram.prototype, "tenantId", 2);
2144
- __decorateClass$2([field({ required: true })], ReferralProgram.prototype, "key", 2);
2135
+ __decorateClass$2([field({
2136
+ required: true,
2137
+ description: "A short name for the program, used in links and reports."
2138
+ })], ReferralProgram.prototype, "key", 2);
2139
+ __decorateClass$2([field({ description: "What you call this program." })], ReferralProgram.prototype, "name", 2);
2140
+ __decorateClass$2([field({ description: "Whether the program is in draft, running or finished." })], ReferralProgram.prototype, "status", 2);
2145
2141
  ReferralProgram = __decorateClass$2([TenantScoped({ mode: "optional" }), smrt({
2146
2142
  conflictColumns: ["tenant_id", "key"],
2147
2143
  api: { include: [
@@ -2356,12 +2352,7 @@ var Referrer = class extends SmrtObject {
2356
2352
  tenantId = null;
2357
2353
  profileId = "";
2358
2354
  earnerId = "";
2359
- /** Human-readable display name for portals and operator views. */
2360
2355
  displayName = "";
2361
- /**
2362
- * Role lifecycle: `pending` (default, awaiting approval) → `active` /
2363
- * `suspended`. Only active referrers should receive new links/agreements.
2364
- */
2365
2356
  status = "pending";
2366
2357
  /**
2367
2358
  * Free-form JSON object stored as a string. Use
@@ -2406,6 +2397,8 @@ __publicField(Referrer, "__smrtPackage__", "@happyvertical/smrt-sales");
2406
2397
  __decorateClass([tenantId({ nullable: true })], Referrer.prototype, "tenantId", 2);
2407
2398
  __decorateClass([crossPackageRef("@happyvertical/smrt-profiles:Profile")], Referrer.prototype, "profileId", 2);
2408
2399
  __decorateClass([foreignKey("Earner")], Referrer.prototype, "earnerId", 2);
2400
+ __decorateClass([field({ description: "The name you know this affiliate by." })], Referrer.prototype, "displayName", 2);
2401
+ __decorateClass([field({ description: "Whether this affiliate is approved to send you referrals." })], Referrer.prototype, "status", 2);
2409
2402
  Referrer = __decorateClass([TenantScoped({ mode: "optional" }), smrt({
2410
2403
  api: { include: [
2411
2404
  "list",
@@ -2447,6 +2440,204 @@ var ReferrerCollection = class extends SmrtCollection {
2447
2440
  }
2448
2441
  };
2449
2442
  //#endregion
2443
+ //#region src/referrals/recipes.ts
2444
+ var AffiliatesReferralsRecipe = class extends SmrtRecipe {
2445
+ static id = "affiliates.referrals";
2446
+ static help = "./referrals.recipe.md";
2447
+ static label = "Affiliates";
2448
+ static summary = "Reward partners for the customers they send you, and pay them what they earn.";
2449
+ static synonyms = [
2450
+ "referrals",
2451
+ "referral program",
2452
+ "partners",
2453
+ "commissions",
2454
+ "payouts",
2455
+ "refer a friend"
2456
+ ];
2457
+ static section = {
2458
+ id: "grow",
2459
+ label: "Grow",
2460
+ icon: "tag",
2461
+ description: "Bring in new customers and reward the people who help."
2462
+ };
2463
+ static models = [
2464
+ Referrer,
2465
+ ReferralProgram,
2466
+ Referral,
2467
+ Earner,
2468
+ Commission,
2469
+ CommissionPayout
2470
+ ];
2471
+ static nav = [
2472
+ {
2473
+ label: "Affiliates",
2474
+ model: Referrer,
2475
+ icon: "users",
2476
+ description: "The partners and customers who send people your way.",
2477
+ noun: "affiliate"
2478
+ },
2479
+ {
2480
+ label: "Programs",
2481
+ model: ReferralProgram,
2482
+ icon: "layers",
2483
+ description: "The offers that decide what a referral earns.",
2484
+ noun: "program"
2485
+ },
2486
+ {
2487
+ label: "Referrals",
2488
+ model: Referral,
2489
+ icon: "repeat",
2490
+ description: "Each person sent to you, and whether it led to a sale."
2491
+ },
2492
+ {
2493
+ label: "Commissions",
2494
+ model: Commission,
2495
+ icon: "receipt",
2496
+ description: "What each affiliate has earned and where it stands."
2497
+ },
2498
+ {
2499
+ label: "Payouts",
2500
+ model: CommissionPayout,
2501
+ icon: "bank",
2502
+ description: "Payments made to affiliates for what they earned."
2503
+ }
2504
+ ];
2505
+ static options = {
2506
+ Referrer: { fields: {
2507
+ displayName: {
2508
+ label: "Name",
2509
+ order: 1
2510
+ },
2511
+ status: { order: 2 },
2512
+ profileId: {
2513
+ label: "Person",
2514
+ visibility: "advanced"
2515
+ },
2516
+ tenantId: { visibility: "hidden" },
2517
+ earnerId: {
2518
+ label: "Payee",
2519
+ visibility: "advanced"
2520
+ },
2521
+ metadata: { visibility: "hidden" }
2522
+ } },
2523
+ ReferralProgram: { fields: {
2524
+ name: { order: 1 },
2525
+ key: {
2526
+ label: "Short name",
2527
+ order: 2
2528
+ },
2529
+ status: { order: 3 },
2530
+ defaultCommissionPlanKey: { visibility: "advanced" },
2531
+ defaultAttributionPolicyKey: { visibility: "advanced" },
2532
+ tenantId: { visibility: "hidden" },
2533
+ metadata: { visibility: "hidden" }
2534
+ } },
2535
+ Referral: { fields: {
2536
+ referrerId: {
2537
+ label: "Affiliate",
2538
+ order: 1
2539
+ },
2540
+ programId: {
2541
+ label: "Program",
2542
+ order: 2
2543
+ },
2544
+ status: { order: 3 },
2545
+ tenantId: { visibility: "hidden" },
2546
+ policyKey: { visibility: "hidden" },
2547
+ policyVersion: { visibility: "hidden" },
2548
+ targetKind: { visibility: "advanced" },
2549
+ targetId: { visibility: "advanced" },
2550
+ creditFraction: { visibility: "advanced" },
2551
+ splitGroupId: { visibility: "hidden" },
2552
+ primaryTouchId: { visibility: "hidden" },
2553
+ attributedAt: { visibility: "advanced" },
2554
+ qualifiedAt: { visibility: "advanced" },
2555
+ expiresAt: { visibility: "advanced" },
2556
+ snapshotId: { visibility: "hidden" },
2557
+ metadata: { visibility: "hidden" }
2558
+ } },
2559
+ Earner: { fields: {
2560
+ displayName: {
2561
+ label: "Name",
2562
+ order: 1
2563
+ },
2564
+ status: { order: 2 },
2565
+ tenantId: { visibility: "hidden" },
2566
+ kind: { visibility: "advanced" },
2567
+ profileId: { visibility: "advanced" },
2568
+ payoutMethod: { visibility: "advanced" },
2569
+ payoutDestination: { visibility: "advanced" },
2570
+ payoutThresholdCents: { visibility: "advanced" },
2571
+ payoutScheduleKey: { visibility: "advanced" },
2572
+ currency: { visibility: "advanced" },
2573
+ metadata: { visibility: "hidden" }
2574
+ } },
2575
+ Commission: { fields: {
2576
+ earnerId: {
2577
+ label: "Affiliate",
2578
+ order: 1
2579
+ },
2580
+ amountCents: {
2581
+ label: "Amount",
2582
+ order: 2
2583
+ },
2584
+ currency: { order: 3 },
2585
+ status: { order: 4 },
2586
+ tenantId: { visibility: "hidden" },
2587
+ earningEventId: { visibility: "hidden" },
2588
+ planKey: { visibility: "advanced" },
2589
+ planVersion: { visibility: "hidden" },
2590
+ componentKey: { visibility: "hidden" },
2591
+ termsSnapshotKind: { visibility: "hidden" },
2592
+ termsSnapshotId: { visibility: "hidden" },
2593
+ basis: { visibility: "advanced" },
2594
+ baseAmountCents: { visibility: "advanced" },
2595
+ rate: { visibility: "advanced" },
2596
+ shareFraction: { visibility: "hidden" },
2597
+ splitGroupId: { visibility: "hidden" },
2598
+ clearingEndsAt: { visibility: "advanced" },
2599
+ earnedAt: { visibility: "advanced" },
2600
+ approvedAt: { visibility: "advanced" },
2601
+ payableAt: { visibility: "advanced" },
2602
+ paidAt: { visibility: "advanced" },
2603
+ payoutId: { visibility: "advanced" },
2604
+ sourceKind: { visibility: "hidden" },
2605
+ sourceId: { visibility: "hidden" },
2606
+ calculationTrace: { visibility: "hidden" },
2607
+ dedupeKey: { visibility: "hidden" },
2608
+ metadata: { visibility: "hidden" }
2609
+ } },
2610
+ CommissionPayout: { fields: {
2611
+ earnerId: {
2612
+ label: "Affiliate",
2613
+ order: 1
2614
+ },
2615
+ totalAmountCents: {
2616
+ label: "Total",
2617
+ order: 2
2618
+ },
2619
+ currency: { order: 3 },
2620
+ status: { order: 4 },
2621
+ paidAt: { order: 5 },
2622
+ tenantId: { visibility: "hidden" },
2623
+ periodStart: { visibility: "advanced" },
2624
+ periodEnd: { visibility: "advanced" },
2625
+ commissionTotalCents: { visibility: "advanced" },
2626
+ adjustmentTotalCents: { visibility: "advanced" },
2627
+ payoutMethod: { visibility: "advanced" },
2628
+ payoutDestination: { visibility: "advanced" },
2629
+ paymentReference: { visibility: "advanced" },
2630
+ providerRef: { visibility: "hidden" },
2631
+ invoiceId: { visibility: "hidden" },
2632
+ notes: { visibility: "advanced" },
2633
+ idempotencyKey: { visibility: "hidden" },
2634
+ sourceKind: { visibility: "hidden" },
2635
+ sourceId: { visibility: "hidden" },
2636
+ metadata: { visibility: "hidden" }
2637
+ } }
2638
+ };
2639
+ };
2640
+ //#endregion
2450
2641
  //#region src/referrals/services/AttributionService.ts
2451
2642
  var MS_PER_DAY = 1440 * 60 * 1e3;
2452
2643
  var QualifiedReferralOverrideError = class extends Error {
@@ -3503,6 +3694,6 @@ var ReferralQualificationService = class ReferralQualificationService {
3503
3694
  }
3504
3695
  };
3505
3696
  //#endregion
3506
- export { ReferralClickOperation as A, ATTRIBUTION_RESOLUTION_MODES as B, ReferralTouchCollection as C, ReferralCollection as D, assertHttpTargetUrl as E, validateAttributionPolicyTerms as F, REFERRAL_STATUSES as G, REFERRAL_AGREEMENT_STATUSES as H, ATTRIBUTION_CONFLICT_BEHAVIORS as I, AttributionExceptionCollection as J, REFERRAL_TOUCH_KINDS as K, ATTRIBUTION_CREDIT_MODES as L, ReferralAgreement as M, AttributionPolicyCollection as N, Referral as O, AttributionPolicy as P, ATTRIBUTION_EXCEPTION_STATUSES as R, generateReferralCode as S, ReferralLink as T, REFERRAL_LINK_STATUSES as U, REFERRAL_AGREEMENT_APPROVAL_MODES as V, REFERRAL_PROGRAM_STATUSES as W, AttributionException as Y, REFERRAL_CODE_ALPHABET as _, ReferralAgreementExecutionService as a, ReferralClickValidationError as b, ReferrerCollection as c, ReferralTermSnapshot as d, ReferralProgramCollection as f, MAX_REFERRAL_CLICK_IDEMPOTENCY_KEY_BYTES as g, MAX_CODE_GENERATION_ATTEMPTS as h, REFERRAL_AGREEMENT_SOURCE_KIND as i, ReferralAgreementCollection as j, ReferralClickOperationCollection as k, Referrer as l, DEFAULT_REFERRAL_CLICK_EVIDENCE_MAX_BYTES as m, REFERRAL_TERMS_SNAPSHOT_KIND as n, AttributionService as o, ReferralProgram as p, REFERRER_STATUSES as q, ReferralCommissionService as r, QualifiedReferralOverrideError as s, ReferralQualificationService as t, ReferralTermSnapshotCollection as u, REFERRAL_CODE_LENGTH as v, ReferralTouch as w, ReferralLinkCollection as x, ReferralClickReplayConflictError as y, ATTRIBUTION_POLICY_STATUSES as z };
3697
+ export { ReferralClickOperationCollection as A, ATTRIBUTION_POLICY_STATUSES as B, generateReferralCode as C, assertHttpTargetUrl as D, ReferralLink as E, AttributionPolicy as F, REFERRAL_PROGRAM_STATUSES as G, REFERRAL_AGREEMENT_APPROVAL_MODES as H, validateAttributionPolicyTerms as I, REFERRER_STATUSES as J, REFERRAL_STATUSES as K, ATTRIBUTION_CONFLICT_BEHAVIORS as L, ReferralAgreementCollection as M, ReferralAgreement as N, ReferralCollection as O, AttributionPolicyCollection as P, ATTRIBUTION_CREDIT_MODES as R, ReferralLinkCollection as S, ReferralTouch as T, REFERRAL_AGREEMENT_STATUSES as U, ATTRIBUTION_RESOLUTION_MODES as V, REFERRAL_LINK_STATUSES as W, AttributionException as X, AttributionExceptionCollection as Y, MAX_REFERRAL_CLICK_IDEMPOTENCY_KEY_BYTES as _, ReferralAgreementExecutionService as a, ReferralClickReplayConflictError as b, AffiliatesReferralsRecipe as c, ReferralTermSnapshotCollection as d, ReferralTermSnapshot as f, MAX_CODE_GENERATION_ATTEMPTS as g, DEFAULT_REFERRAL_CLICK_EVIDENCE_MAX_BYTES as h, REFERRAL_AGREEMENT_SOURCE_KIND as i, ReferralClickOperation as j, Referral as k, ReferrerCollection as l, ReferralProgram as m, REFERRAL_TERMS_SNAPSHOT_KIND as n, AttributionService as o, ReferralProgramCollection as p, REFERRAL_TOUCH_KINDS as q, ReferralCommissionService as r, QualifiedReferralOverrideError as s, ReferralQualificationService as t, Referrer as u, REFERRAL_CODE_ALPHABET as v, ReferralTouchCollection as w, ReferralClickValidationError as x, REFERRAL_CODE_LENGTH as y, ATTRIBUTION_EXCEPTION_STATUSES as z };
3507
3698
 
3508
- //# sourceMappingURL=referrals-BPEaXqCz.js.map
3699
+ //# sourceMappingURL=referrals-o8qZG5fw.js.map