@cofondateurauchomage/libs 1.1.153 → 1.1.156

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.
@@ -108,11 +108,12 @@ type ICrmUserProfileSnapshot = Omit<IUser, "photo" | "motivations" | "bestStreng
108
108
  /** CRM mirror of `projects/{id}` without heavy assets or long text fields. */
109
109
  type ICrmProjectProfileSnapshot = Omit<IProject, "logo" | "description" | "partner" | "status_detail" | "clicks">;
110
110
  /** CRM pipeline column; computed server-side from profile + billing state. */
111
- export type TCrmPipelineBucket = "lead" | "inscrit" | "pro" | "ancien_pro";
111
+ export type TCrmPipelineBucket = "prospect" | "inscrit" | "pro" | "ancien_pro";
112
112
  interface ICrmProfileBase {
113
113
  pipelineBucket: TCrmPipelineBucket;
114
114
  searchText: string;
115
- lastTeamCallAt?: number;
115
+ /** 0 if not called */
116
+ lastTeamCallAt: number;
116
117
  foundPartner?: boolean;
117
118
  }
118
119
  export interface ICrmProfileProspect extends ICrmProfileBase {
@@ -0,0 +1,14 @@
1
+ import type { ICrmProfile, ICrmProfileProject, ICrmProfileUser, IStripeMeta, TCrmPlanFilter, TPlan } from "../db.model";
2
+ type PlanPick = {
3
+ plan: TPlan;
4
+ complimentaryProGrantedAt?: number;
5
+ complimentaryProRevokedAt?: number;
6
+ };
7
+ /**
8
+ * Maps profile + Stripe mirror to a CRM pipeline plan filter bucket.
9
+ * Mirrors front-v2 `resolveCrmPlanBadgeModel` (free / paid Pro / complimentary Pro).
10
+ */
11
+ export declare function resolveCrmPlanFilterForUserOrProject(profile: PlanPick, stripe: Partial<IStripeMeta> | undefined): TCrmPlanFilter;
12
+ export declare function resolveCrmPlanFilterFromUserOrProjectDoc(doc: ICrmProfileUser | ICrmProfileProject): TCrmPlanFilter;
13
+ export declare function resolveCrmPlanFilter(profile: ICrmProfile): TCrmPlanFilter;
14
+ export {};
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveCrmPlanFilterForUserOrProject = resolveCrmPlanFilterForUserOrProject;
4
+ exports.resolveCrmPlanFilterFromUserOrProjectDoc = resolveCrmPlanFilterFromUserOrProjectDoc;
5
+ exports.resolveCrmPlanFilter = resolveCrmPlanFilter;
6
+ const PRO_PLANS = new Set(["pro", "premium"]);
7
+ function derivePaymentBadge(profile) {
8
+ const now = Date.now();
9
+ const periodEnd = profile.stripeCurrentPeriodEnd;
10
+ const payingPeriod = (profile.plan === "pro" || profile.plan === "premium") &&
11
+ periodEnd != null &&
12
+ periodEnd > now &&
13
+ profile.stripeLastPaymentAt != null;
14
+ if (payingPeriod) {
15
+ return "payant";
16
+ }
17
+ if (profile.stripeFirstPaidAt != null) {
18
+ return "ancien_payant";
19
+ }
20
+ return null;
21
+ }
22
+ function stripeBillingFields(profile, stripe) {
23
+ return {
24
+ plan: profile.plan,
25
+ stripeFirstPaidAt: stripe?.stripeFirstPaidAt,
26
+ stripeLastPaymentAt: stripe?.stripeLastPaymentAt,
27
+ stripeCurrentPeriodEnd: stripe?.stripeCurrentPeriodEnd,
28
+ stripeSubscriptionEndedAt: stripe?.stripeSubscriptionEndedAt,
29
+ };
30
+ }
31
+ /**
32
+ * Maps profile + Stripe mirror to a CRM pipeline plan filter bucket.
33
+ * Mirrors front-v2 `resolveCrmPlanBadgeModel` (free / paid Pro / complimentary Pro).
34
+ */
35
+ function resolveCrmPlanFilterForUserOrProject(profile, stripe) {
36
+ const stripeMeta = stripe ?? {};
37
+ const billing = stripeBillingFields(profile, stripeMeta);
38
+ const payBadge = derivePaymentBadge(billing);
39
+ const compAt = profile.complimentaryProGrantedAt;
40
+ const compRevoked = profile.complimentaryProRevokedAt != null && profile.complimentaryProRevokedAt > 0;
41
+ const plan = profile.plan;
42
+ if (PRO_PLANS.has(plan)) {
43
+ if (payBadge === "payant") {
44
+ return "pro";
45
+ }
46
+ if (compAt != null && compAt > 0 && !compRevoked) {
47
+ return "pro_offert";
48
+ }
49
+ return "pro";
50
+ }
51
+ if (compRevoked) {
52
+ return "free";
53
+ }
54
+ const endedAt = stripeMeta.stripeSubscriptionEndedAt != null && stripeMeta.stripeSubscriptionEndedAt > 0
55
+ ? stripeMeta.stripeSubscriptionEndedAt
56
+ : undefined;
57
+ if (payBadge === "ancien_payant" || stripeMeta.stripeFirstPaidAt != null || endedAt != null) {
58
+ return "free";
59
+ }
60
+ return "free";
61
+ }
62
+ function resolveCrmPlanFilterFromUserOrProjectDoc(doc) {
63
+ return resolveCrmPlanFilterForUserOrProject({
64
+ plan: doc.profile.plan,
65
+ complimentaryProGrantedAt: doc.complimentaryProGrantedAt,
66
+ complimentaryProRevokedAt: doc.complimentaryProRevokedAt,
67
+ }, doc.stripeMeta);
68
+ }
69
+ function resolveCrmPlanFilter(profile) {
70
+ if (profile.type === "prospect") {
71
+ return "free";
72
+ }
73
+ return resolveCrmPlanFilterFromUserOrProjectDoc(profile);
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofondateurauchomage/libs",
3
- "version": "1.1.153",
3
+ "version": "1.1.156",
4
4
  "description": "",
5
5
  "main": "build/index",
6
6
  "scripts": {