@wirecat/cli-core 0.587.0 → 0.589.0

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 (41) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/cli/messenger/search-answers.js +3 -0
  3. package/dist/cli/messenger/store-maintenance-command.d.ts +1 -1
  4. package/dist/domain/deals.d.ts +8 -6
  5. package/dist/domain/deals.js +7 -8
  6. package/dist/domain/providers.d.ts +7 -1
  7. package/dist/domain/providers.js +3 -1
  8. package/dist/domain/ref-summaries.js +2 -0
  9. package/dist/domain/references.d.ts +1 -1
  10. package/dist/domain/references.js +2 -0
  11. package/dist/entities/hit.d.ts +2 -2
  12. package/dist/entities/hit.js +2 -2
  13. package/dist/entities/index.d.ts +1 -1
  14. package/dist/errors/reasons.js +6 -6
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +2 -2
  17. package/dist/search/account-list.js +1 -0
  18. package/dist/services/project-status/index.d.ts +1 -1
  19. package/dist/services/project-status/index.js +13 -12
  20. package/dist/services/project-status/signals/amounts.d.ts +1 -0
  21. package/dist/services/project-status/signals/amounts.js +4 -3
  22. package/dist/services/project-status/types.d.ts +2 -0
  23. package/dist/services/proposals/registry.js +0 -2
  24. package/dist/services/search-all-meetings.d.ts +1 -1
  25. package/dist/services/search-all-meetings.js +1 -0
  26. package/dist/services/search-all.d.ts +15 -5
  27. package/dist/services/search-all.js +46 -3
  28. package/dist/store/index.d.ts +1 -1
  29. package/dist/store/sqlite/deals.d.ts +142 -29
  30. package/dist/store/sqlite/deals.js +295 -156
  31. package/dist/store/sqlite/entity-types.d.ts +3 -1
  32. package/dist/store/sqlite/entity-types.js +3 -1
  33. package/dist/store/sqlite/knowledge.js +3 -1
  34. package/dist/store/sqlite/migrations.generated.js +39 -11
  35. package/dist/store/sqlite/ref-summaries.js +11 -7
  36. package/dist/store/sqlite/schema.d.ts +600 -38
  37. package/dist/store/sqlite/schema.js +86 -14
  38. package/dist/store/sqlite/things.js +2 -0
  39. package/package.json +1 -1
  40. package/dist/services/proposals/kinds/deals.d.ts +0 -4
  41. package/dist/services/proposals/kinds/deals.js +0 -32
@@ -1,31 +1,62 @@
1
- import { type DealRole, type DealStatus } from "../../domain/deals.js";
2
- import { type FinanceReview } from "../../domain/finance.js";
3
- import { type Decider } from "../decisions.js";
1
+ import { type DealKind, type DealRole, type DealStatus, type StageOutcome } from "../../domain/deals.js";
2
+ import type { AccountKey } from "../types.js";
4
3
  import { type ProposedByFilter } from "./actors.js";
5
- import { type Party, type Reviewed, type Written } from "./finance.js";
4
+ import { type Party } from "./finance.js";
6
5
  import { type Author } from "./memories.js";
7
6
  import type { StoreContext } from "./open.js";
8
7
  export interface PipelineStage {
9
8
  name: string;
10
9
  position: number;
11
- /** Open deals standing in it, the owner's and agents' not rejected. */
10
+ outcome: StageOutcome;
11
+ externalId: string | null;
12
+ /** Open deals or leads standing in it now. */
12
13
  open: number;
13
14
  }
14
15
  export interface Pipeline {
16
+ id: string;
17
+ ref: string;
15
18
  name: string;
19
+ kind: DealKind;
20
+ /** The CRM account it was copied from; `null` for the owner's or an agent's own. */
21
+ account: {
22
+ provider: string;
23
+ account: string;
24
+ } | null;
25
+ externalId: string | null;
16
26
  stages: PipelineStage[];
17
27
  createdAt: string;
18
28
  }
29
+ export interface FunnelStage extends PipelineStage {
30
+ /** Rows that got this far: entered this stage or a later one that is not lost, or were won. */
31
+ reached: number;
32
+ /** `reached` of the next stage that is not lost over this stage's, 0–1; `null` for the last or an empty one. */
33
+ conversion: number | null;
34
+ }
35
+ /** A pipeline with its funnel, counted from `pipeline_stage_changes`. */
36
+ export interface PipelineReport extends Omit<Pipeline, "stages"> {
37
+ stages: FunnelStage[];
38
+ totals: {
39
+ items: number;
40
+ open: number;
41
+ won: number;
42
+ lost: number;
43
+ winRate: number | null;
44
+ };
45
+ /** `YYYY-MM-DD`: only rows made since that day are counted; `null` for all. */
46
+ since: string | null;
47
+ }
19
48
  export interface DealPerson extends Party {
20
49
  role: DealRole;
21
50
  }
22
- export interface Deal extends Reviewed {
51
+ export interface Deal {
23
52
  id: string;
24
53
  ref: string;
54
+ kind: DealKind;
25
55
  title: string;
26
- /** One line with stage, amount and status, as a list or the review inbox prints it. */
56
+ /** One line with stage, amount and status, as a list prints it. */
27
57
  summary: string;
28
58
  pipeline: string;
59
+ pipelineName: string;
29
60
  stage: string;
30
61
  status: DealStatus;
31
62
  organization: Party | null;
@@ -36,14 +67,44 @@ export interface Deal extends Reviewed {
36
67
  closeDate: string | null;
37
68
  /** `YYYY-MM-DD`: the day it was won or lost. */
38
69
  closedDate: string | null;
39
- /** Why it was won or lost, as the owner said when closing it. */
70
+ /** Why it was won or lost, as given when closing it. */
40
71
  closedReason: string | null;
72
+ rank: number | null;
73
+ /** A lead's deal, once it became one. */
74
+ deal: string | null;
75
+ account: {
76
+ provider: string;
77
+ account: string;
78
+ } | null;
79
+ externalId: string | null;
41
80
  people: DealPerson[];
81
+ author: {
82
+ type: "person" | "bot";
83
+ id: string;
84
+ name: string | null;
85
+ kind: "agent" | "rule" | null;
86
+ };
87
+ model: string | null;
88
+ source: string;
89
+ reason: string | null;
90
+ evidence: string[];
91
+ project: string | null;
92
+ projectName: string | null;
93
+ createdAt: string;
94
+ updatedAt: string;
42
95
  }
43
- export interface DealInput extends Written {
96
+ export interface DealInput {
97
+ /** Who writes it; the owner and an agent write alike, and only the author is kept. */
98
+ by: Author;
99
+ /** `deal` when left out. */
100
+ kind?: DealKind;
44
101
  title: string;
45
- /** A stage's name; `pipeline` names its pipeline when more than one has a stage of that name. */
46
- stage: string;
102
+ /**
103
+ * A stage's name, in `pipeline` when given, else in the only pipeline of the kind that has it. A lead may leave it
104
+ * out when there is one lead pipeline: it starts in that pipeline's first stage.
105
+ */
106
+ stage?: string;
107
+ /** `pipeline:<id>`, or a name only one pipeline of the kind has. */
47
108
  pipeline?: string;
48
109
  organization?: string;
49
110
  /** A decimal string in `currency`; give both or neither. */
@@ -54,51 +115,103 @@ export interface DealInput extends Written {
54
115
  person: string;
55
116
  role: DealRole;
56
117
  }[];
118
+ project?: string;
119
+ /** Where an agent's row came from, such as `agent`; the owner's is always `owner`. */
120
+ source?: string;
121
+ reason?: string;
122
+ evidence?: string[];
57
123
  }
58
124
  export interface DealFilter {
125
+ /** `deal` when left out. */
126
+ kind?: DealKind;
59
127
  status?: DealStatus;
60
- /** A stage's or pipeline's name, in any letter case. */
128
+ /** A stage's name, in any letter case. */
61
129
  stage?: string;
130
+ /** `pipeline:<id>`, or a name only one pipeline of the kind has. */
62
131
  pipeline?: string;
63
132
  project?: string;
64
133
  organization?: string;
65
- review?: FinanceReview;
66
134
  proposedBy?: ProposedByFilter;
67
135
  /** 1–500, 100 by default; newest written first. */
68
136
  limit?: number;
69
137
  }
138
+ export interface DealSearch {
139
+ /** Words of the title, each in any letter case; a word may be a phrase. */
140
+ words: string[];
141
+ /** A title holding any of the words matches, those holding more first; otherwise every word is needed. */
142
+ anyWord?: boolean;
143
+ /** Only the copies of these CRM accounts; absent, every account's and the owner's own. */
144
+ accounts?: AccountKey[];
145
+ /** 1–500, 100 by default. */
146
+ limit?: number;
147
+ }
148
+ export interface PipelineInput {
149
+ name: string;
150
+ /** `deal` when left out. */
151
+ kind?: DealKind;
152
+ /** In order; a bare name is an open stage. */
153
+ stages: (string | {
154
+ name: string;
155
+ outcome?: StageOutcome;
156
+ })[];
157
+ by: Author;
158
+ }
70
159
  /**
71
- * The owner's sales pipelines and the deals in them. The owner's deal is confirmed at once; an agent's waits as
72
- * proposed for him, and only he decides it. Only the owner makes a pipeline, moves a deal or closes it.
160
+ * Sales pipelines and the deals and leads in them. The owner and his agents write alike: nothing waits for review,
161
+ * and memo's permission settings are where writes are limited. Every stage a row enters is kept, by triggers, so a
162
+ * pipeline's report counts conversion between stages.
73
163
  */
74
164
  export interface DealsStore {
75
- addPipeline(input: {
76
- name: string;
77
- stages: string[];
78
- by: Author;
79
- }): Promise<Pipeline>;
80
- pipelines(): Promise<Pipeline[]>;
165
+ addPipeline(input: PipelineInput): Promise<Pipeline>;
166
+ pipelines(filter?: {
167
+ kind?: DealKind;
168
+ }): Promise<Pipeline[]>;
169
+ /** One pipeline by `pipeline:<id>` or a name only one pipeline has, with its funnel. */
170
+ pipeline(reference: string, options?: {
171
+ kind?: DealKind;
172
+ since?: string;
173
+ }): Promise<PipelineReport>;
81
174
  add(input: DealInput): Promise<Deal>;
175
+ /** `deal:<id>` or `lead:<id>`; a bare id is a deal. */
82
176
  get(reference: string): Promise<Deal>;
83
177
  list(filter?: DealFilter): Promise<Deal[]>;
84
- /** To another stage of the deal's own pipeline. */
178
+ /** Deals and leads together, by the words of their title: the most words matched first, then the latest changed. */
179
+ find(search: DealSearch): Promise<Deal[]>;
180
+ /** To another stage of its own pipeline; a stage whose outcome is won or lost closes it, an open one reopens it. */
85
181
  move(reference: string, input: {
86
182
  stage: string;
87
183
  by: Author;
88
184
  }): Promise<Deal>;
89
- /** `date` is the day it closed, today when left out. */
185
+ /** Won or lost, on `date` (today when left out); it moves to its pipeline's stage of that outcome when there is one. */
90
186
  close(reference: string, input: {
91
187
  status: Exclude<DealStatus, "open">;
92
188
  date?: string;
93
189
  reason?: string;
94
190
  by: Author;
95
191
  }): Promise<Deal>;
96
- confirm(reference: string, by: Decider, reason?: string): Promise<Deal>;
97
- reject(reference: string, by: Decider, reason?: string): Promise<Deal>;
98
192
  }
99
- type DealOperations = {
100
- [K in keyof DealsStore]: DealsStore[K] extends (...args: infer A) => Promise<infer R> ? (...args: A) => R : never;
193
+ export declare const dealOperationsOver: (context: StoreContext) => {
194
+ addPipeline: ({ name, kind, stages, by }: PipelineInput) => Pipeline;
195
+ pipelines: (filter?: {
196
+ kind?: DealKind;
197
+ }) => Pipeline[];
198
+ pipeline: (reference: string, options?: {
199
+ kind?: DealKind;
200
+ since?: string;
201
+ }) => PipelineReport;
202
+ add: (input: DealInput) => Deal;
203
+ get: (reference: string) => Deal;
204
+ list: (filter?: DealFilter) => Deal[];
205
+ find: ({ words, anyWord, accounts, limit }: DealSearch) => Deal[];
206
+ move: (reference: string, { stage, by }: {
207
+ stage: string;
208
+ by: Author;
209
+ }) => Deal;
210
+ close: (reference: string, { status, date, reason, by }: {
211
+ status: Exclude<DealStatus, "open">;
212
+ date?: string;
213
+ reason?: string;
214
+ by: Author;
215
+ }) => Deal;
101
216
  };
102
- export declare const dealOperationsOver: (context: StoreContext) => DealOperations;
103
217
  export declare const dealsStoreOver: (context: StoreContext) => DealsStore;
104
- export {};