@wirecat/cli-core 0.675.0 → 0.677.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 (74) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/dist/calendar/mcp/index.d.ts +12 -12
  3. package/dist/cli/command-runs.d.ts +2 -0
  4. package/dist/cli/command-runs.js +2 -0
  5. package/dist/cli/documents/words.d.ts +1 -1
  6. package/dist/cli/index.d.ts +2 -2
  7. package/dist/cli/index.js +1 -1
  8. package/dist/cli/list-query.d.ts +3 -2
  9. package/dist/cli/list-query.js +5 -2
  10. package/dist/cli/setup-command.js +9 -3
  11. package/dist/crm/cli/index.d.ts +7 -1
  12. package/dist/crm/cli/index.js +104 -20
  13. package/dist/crm/cli/pipeline-view.js +15 -1
  14. package/dist/crm/cli/records.js +11 -3
  15. package/dist/crm/cli/search-all.d.ts +5 -2
  16. package/dist/crm/cli/search-all.js +15 -3
  17. package/dist/crm/source.d.ts +3 -2
  18. package/dist/crm/stage-tasks.js +1 -1
  19. package/dist/crm/sync.js +13 -11
  20. package/dist/crm/testing/write-contract.js +5 -1
  21. package/dist/crm/viewer.d.ts +28 -0
  22. package/dist/crm/viewer.js +63 -0
  23. package/dist/crm/writer.d.ts +3 -0
  24. package/dist/crm/writes.d.ts +7 -2
  25. package/dist/crm/writes.js +24 -14
  26. package/dist/domain/crm.d.ts +9 -9
  27. package/dist/domain/moment.d.ts +2 -0
  28. package/dist/domain/moment.js +2 -0
  29. package/dist/entities/business-context.js +1 -1
  30. package/dist/entities/deal.d.ts +86 -39
  31. package/dist/entities/deal.js +45 -4
  32. package/dist/entities/index.d.ts +20 -32
  33. package/dist/errors/reasons.js +2 -0
  34. package/dist/meetings/mcp/index.d.ts +15 -15
  35. package/dist/services/metadata.d.ts +1 -1
  36. package/dist/services/search-all.d.ts +3 -1
  37. package/dist/services/search-all.js +1 -0
  38. package/dist/setup/define.d.ts +17 -2
  39. package/dist/store/exports.d.ts +1 -0
  40. package/dist/store/exports.js +1 -0
  41. package/dist/store/identity-links.d.ts +73 -0
  42. package/dist/store/identity-links.js +14 -0
  43. package/dist/store/index.d.ts +1 -1
  44. package/dist/store/index.js +1 -1
  45. package/dist/store/people.d.ts +23 -1
  46. package/dist/store/people.js +12 -1
  47. package/dist/store/sqlite/agent-links.d.ts +34 -0
  48. package/dist/store/sqlite/agent-links.js +184 -0
  49. package/dist/store/sqlite/copy-viewer.d.ts +16 -0
  50. package/dist/store/sqlite/copy-viewer.js +11 -0
  51. package/dist/store/sqlite/crm-activities.d.ts +7 -1
  52. package/dist/store/sqlite/crm-activities.js +32 -5
  53. package/dist/store/sqlite/crm-contacts.d.ts +5 -2
  54. package/dist/store/sqlite/crm-contacts.js +30 -14
  55. package/dist/store/sqlite/crm-rows.d.ts +7 -0
  56. package/dist/store/sqlite/crm-rows.js +37 -5
  57. package/dist/store/sqlite/crm-settings.d.ts +2 -1
  58. package/dist/store/sqlite/crm-settings.js +3 -2
  59. package/dist/store/sqlite/crm-stage-entries.d.ts +24 -4
  60. package/dist/store/sqlite/crm-stage-entries.js +77 -18
  61. package/dist/store/sqlite/crm.d.ts +14 -4
  62. package/dist/store/sqlite/crm.js +59 -7
  63. package/dist/store/sqlite/deals.d.ts +47 -29
  64. package/dist/store/sqlite/deals.js +64 -76
  65. package/dist/store/sqlite/identity-proposals.d.ts +2 -0
  66. package/dist/store/sqlite/identity-proposals.js +2 -0
  67. package/dist/store/sqlite/person-match-scan.d.ts +29 -0
  68. package/dist/store/sqlite/person-match-scan.js +4 -4
  69. package/dist/store/sqlite/person-merges.d.ts +3 -0
  70. package/dist/store/sqlite/pipeline-period.d.ts +85 -0
  71. package/dist/store/sqlite/pipeline-period.js +199 -0
  72. package/dist/store/sqlite/stage-amounts.d.ts +6 -2
  73. package/dist/store/sqlite/stage-amounts.js +8 -5
  74. package/package.json +3 -3
@@ -5,7 +5,7 @@ import type { AppIdentity } from "../ports/app.js";
5
5
  import type { Warn } from "../runs/events.js";
6
6
  import { type Asker, type GuardSettings } from "../sends/guard.js";
7
7
  import { type PermissionKey } from "../sends/permissions.js";
8
- import type { Deal, PipelineReport } from "../store/sqlite/deals.js";
8
+ import type { Deal, PipelineOptions, PipelineReport } from "../store/sqlite/deals.js";
9
9
  import type { MessageStore } from "../store/store.js";
10
10
  import type { AccountKey } from "../store/types.js";
11
11
  import type { CrmSource } from "./source.js";
@@ -58,7 +58,7 @@ export interface CrmFieldsInput {
58
58
  custom?: readonly (readonly [name: string, value: string])[];
59
59
  }
60
60
  /** The named pipeline of this profile's CRM account, or its only one; several and none named is refused. */
61
- export declare const pipelineOf: (context: Pick<CrmWriteContext, "store" | "account">, kind: DealKind | undefined, reference: string | undefined, param?: string) => Promise<PipelineReport>;
61
+ export declare const pipelineOf: (context: Pick<CrmWriteContext, "store" | "account">, kind: DealKind | undefined, reference: string | undefined, param?: string, window?: Pick<PipelineOptions, "since" | "until" | "zone" | "viewer">) => Promise<PipelineReport>;
62
62
  /** What the field lookup reads of a field definition: a CRM CLI's own type fits. */
63
63
  export type NamedField = Pick<CrmField, "code" | "label" | "options">;
64
64
  /**
@@ -123,6 +123,11 @@ export interface CrmRecordWritten<K extends CrmRecordKind> {
123
123
  record: K extends "person" ? CrmPerson : CrmOrganization;
124
124
  /** Whether the copy keeps it: only the sign-in's own clients are stored (NEED-2661). */
125
125
  stored: boolean;
126
+ /**
127
+ * After an update that gave it to someone else, whether the copy let it go: `false` when it stays, because the
128
+ * owner decided about the contact, something else points at it, or one of the owner's deals names it.
129
+ */
130
+ removed?: boolean;
126
131
  }
127
132
  /** A CRM id as a list prints it; shared with the commands, not exported from the package. */
128
133
  export declare const RECORD_ID: RegExp;
@@ -1,5 +1,6 @@
1
1
  import { CliError, isCliError } from "@wirecat/cli-base";
2
2
  import { currencyOf, minorUnits } from "../domain/money.js";
3
+ import { e164Of } from "../domain/phones.js";
3
4
  import { foldName } from "../resolve.js";
4
5
  import { guardFor } from "../sends/guard.js";
5
6
  import { guardedWrite } from "../sends/guarded.js";
@@ -73,8 +74,8 @@ const copyOf = async (context, kind, reference) => {
73
74
  return found;
74
75
  };
75
76
  /** The named pipeline of this profile's CRM account, or its only one; several and none named is refused. */
76
- export const pipelineOf = async (context, kind, reference, param = "--pipeline") => {
77
- const scope = { ...(kind ? { kind } : {}), account: context.account };
77
+ export const pipelineOf = async (context, kind, reference, param = "--pipeline", window = {}) => {
78
+ const scope = { ...window, ...(kind ? { kind } : {}), account: context.account };
78
79
  if (reference !== undefined) {
79
80
  const found = await context.store.deals.pipeline(reference, scope);
80
81
  if (found.externalId === null)
@@ -377,7 +378,7 @@ export const removeCrmItem = async (context, kind, reference, options = {}) => {
377
378
  const EMAIL = /^[^\s@]{1,64}@[^\s@]{1,255}$/u;
378
379
  /** A CRM id as a list prints it; shared with the commands, not exported from the package. */
379
380
  export const RECORD_ID = /^[\w.:-]{1,100}$/u;
380
- const PERSON_ONLY = ["firstName", "lastName", "position", "emails", "phones"];
381
+ const PERSON_ONLY = ["firstName", "lastName", "position"];
381
382
  const recordInvalid = (message, param) => new CliError("validation_error", message, { reason: "crm.record-field", ...(param ? { param } : {}) });
382
383
  const cleared = (value) => (value === undefined ? undefined : value.trim() || null);
383
384
  const listed = (values, param, valid) => {
@@ -391,7 +392,7 @@ const listed = (values, param, valid) => {
391
392
  throw recordInvalid(`${param} got ${one}`, param);
392
393
  return all;
393
394
  };
394
- /** Typed fields into the port's; a company takes only a name, an owner and its own fields. */
395
+ /** Typed fields into the port's; a company takes no name parts and no position. */
395
396
  const recordFieldsOf = (kind, input) => {
396
397
  if (kind === "organization") {
397
398
  const given = PERSON_ONLY.find((one) => input[one] !== undefined);
@@ -413,7 +414,12 @@ const recordFieldsOf = (kind, input) => {
413
414
  if (position !== undefined)
414
415
  fields.position = position;
415
416
  const emails = listed(input.emails, "--email", EMAIL);
416
- const phones = listed(input.phones, "--phone");
417
+ const phones = listed(input.phones, "--phone")?.map((phone) => {
418
+ const international = e164Of(phone, undefined);
419
+ if (typeof international !== "string")
420
+ throw recordInvalid(`--phone takes a number in international form, starting with +: not ${phone}`, "--phone");
421
+ return international;
422
+ });
417
423
  if (emails)
418
424
  fields.emails = emails;
419
425
  if (phones)
@@ -441,25 +447,24 @@ const keptRecord = async (context, kind, record) => {
441
447
  }
442
448
  };
443
449
  /**
444
- * A company the update gave to someone else leaves the copy (NEED-2661), as `removeCrmItem` removes a deal. A contact
445
- * stays until a sync's scope removes it: the store has no removal of one contact by id, and its identity keeps the
446
- * phones and e-mails it was saved with.
450
+ * A contact or company the update gave to someone else leaves the copy (NEED-2661), as `removeCrmItem` removes a deal:
451
+ * a contact with its identity, which held the phones and e-mails it was saved with.
447
452
  */
448
- const forgotten = async (context, kind, record) => {
449
- if (kind === "organization")
450
- await context.store.crm.remove(context.account, kind, [record.externalId]);
451
- };
453
+ const forgotten = async (context, kind, record) => (kind === "organization"
454
+ ? await context.store.crm.remove(context.account, kind, [record.externalId])
455
+ : (await context.store.crm.removeContact(context.account, record.externalId)).contacts) > 0;
452
456
  const writeRecord = async (context, kind, verb, fields, operationId, act) => {
453
457
  if (!context.source)
454
458
  throw new CliError("configuration_error", "a contact or company write needs the CRM source to tell your clients");
455
459
  const rule = foreignContacts(context.source(), undefined);
456
460
  const record = await written(context, keysOf(context, kind, verb, { owner: fields.owner }), operationId, act);
457
461
  const stored = await rule.own(kind, record);
462
+ let removed;
458
463
  try {
459
464
  if (stored)
460
465
  await keptRecord(context, kind, record);
461
466
  else if (verb === "update")
462
- await forgotten(context, kind, record);
467
+ removed = await forgotten(context, kind, record);
463
468
  }
464
469
  catch (error) {
465
470
  if (isCliError(error))
@@ -467,7 +472,12 @@ const writeRecord = async (context, kind, verb, fields, operationId, act) => {
467
472
  throw error;
468
473
  }
469
474
  const [shown] = stored ? [record] : await rule.strip(kind, [record]);
470
- return { operationId, record: shown, stored };
475
+ return {
476
+ operationId,
477
+ record: shown,
478
+ stored,
479
+ ...(removed === undefined ? {} : { removed }),
480
+ };
471
481
  };
472
482
  /** A new contact or company in the CRM, through the guarded path; the CRM's answer is stored as a sync stores it. */
473
483
  export const createCrmRecord = async (context, kind, input, options = {}) => {
@@ -104,8 +104,8 @@ export interface CrmPerson {
104
104
  /** The CRM user the contact is assigned to: under `mine`, one assigned to a user in scope stays with no deal. */
105
105
  assignee?: string | null;
106
106
  /**
107
- * What a live read (`CrmSource.list`, `get`) and a write answer give beside the copy's fields; the store keeps only
108
- * `assignee` of them. Times are epoch ms; `url` is the CRM's own page for it.
107
+ * What a live read (`CrmSource.list`, `get`) and a write answer give beside the copy's fields; the store keeps them
108
+ * too, a field left out keeping its stored value. Times are epoch ms; `url` is the CRM's own page for it.
109
109
  */
110
110
  createdAt?: number | null;
111
111
  updatedAt?: number | null;
@@ -133,8 +133,8 @@ export interface CrmOrganization {
133
133
  /** A live read's contacts of the company, by their id. */
134
134
  people?: string[];
135
135
  /**
136
- * What a live read (`CrmSource.list`, `get`) and a write answer give beside the copy's fields; the store does not keep
137
- * them. `assignee` is the CRM user it is assigned to; times are epoch ms; `url` the CRM's own page for it.
136
+ * What a live read (`CrmSource.list`, `get`) and a write answer give beside the copy's fields; the store keeps them,
137
+ * one left out keeping its stored value. `assignee` is the CRM user it is assigned to; times are epoch ms.
138
138
  */
139
139
  assignee?: string | null;
140
140
  createdAt?: number | null;
@@ -192,9 +192,9 @@ export interface CrmRecords {
192
192
  export declare const CRM_ACTIVITY_KINDS: readonly ["call", "email", "meeting", "todo", "task", "comment", "other"];
193
193
  export type CrmActivityKind = (typeof CRM_ACTIVITY_KINDS)[number];
194
194
  /**
195
- * An activity on the CRM's deals and leads, as the CRM has it. `externalId` is unique among the account's activities
196
- * of every kind (a source with separate lists prefixes them). Contact data the CRM keeps on it, such as a call's
197
- * phone number, is never part of it: it would bypass the limits on reading clients' contacts.
195
+ * An activity on the CRM's deals, leads, contacts and companies, as the CRM has it. `externalId` is unique among the
196
+ * account's activities of every kind (a source with separate lists prefixes them). Contact data the CRM keeps on it,
197
+ * such as a call's phone number, is never part of it: it would bypass the limits on reading clients' contacts.
198
198
  */
199
199
  export interface CrmActivity {
200
200
  externalId: string;
@@ -209,9 +209,9 @@ export interface CrmActivity {
209
209
  assignee?: string | null;
210
210
  createdAt: number;
211
211
  updatedAt: number;
212
- /** The deals and leads it is on, by the CRM's ids; one on neither is not stored. */
212
+ /** The deals, leads, contacts and companies it is on, by the CRM's ids; one on none the copy holds is not stored. */
213
213
  on: {
214
- kind: DealKind;
214
+ kind: CrmKind;
215
215
  externalId: string;
216
216
  }[];
217
217
  }
@@ -6,6 +6,8 @@ export interface MomentZone {
6
6
  }
7
7
  /** A typed date or time as epoch ms, with the flag named when it is not one. */
8
8
  export declare const calendarMoment: (wanted: string, flag: string, { zone, end }?: MomentZone) => number;
9
+ /** The `YYYY-MM-DD` day `at` falls on in `zone`. */
10
+ export declare const dayIn: (at: number, zone: string) => string;
9
11
  export declare const MINUTE = 60000;
10
12
  export declare const YEAR: number;
11
13
  export interface Reading {
@@ -12,6 +12,8 @@ export const calendarMoment = (wanted, flag, { zone, end = false } = {}) => {
12
12
  throw new CliError("validation_error", `${flag}: "${wanted}" is not a time${alternative ? ` — ${alternative}` : ""}`);
13
13
  }
14
14
  };
15
+ /** The `YYYY-MM-DD` day `at` falls on in `zone`. */
16
+ export const dayIn = (at, zone) => new Intl.DateTimeFormat("en-CA", { timeZone: zone, year: "numeric", month: "2-digit", day: "2-digit" }).format(at);
15
17
  export const MINUTE = 60_000;
16
18
  export const YEAR = 365 * 24 * 60 * MINUTE;
17
19
  const RELATIVE = /^(\d+)(m|h|d)$/;
@@ -147,7 +147,7 @@ const { untrusted: _, ...dealRow } = deal.entries;
147
147
  /** One deal or lead: the row, its stages, client, people, project, money and what its people said in its time. */
148
148
  export const dealContext = v.strictObject({
149
149
  deal: v.strictObject(dealRow),
150
- stages: section(v.strictObject({ from: nullableText, to: text, pipeline: reference, at: time })),
150
+ stages: section(v.strictObject({ from: nullableText, to: text, pipeline: reference, at: time, exact: v.boolean() })),
151
151
  organization: v.nullable(v.strictObject({ ref: reference, name: nullableText, categories })),
152
152
  participants: section(related),
153
153
  owner: v.nullable(related),
@@ -12,6 +12,13 @@ export interface DealActivity {
12
12
  created_at: string;
13
13
  updated_at: string;
14
14
  }
15
+ /** One stage a deal or lead entered: `exact` from the CRM's own history, else as a sync saw the copy change. */
16
+ export interface DealStageEntry {
17
+ from: string | null;
18
+ to: string;
19
+ at: string;
20
+ exact: boolean;
21
+ }
15
22
  /**
16
23
  * A deal (`deal:<id>`), the owner's own or a CRM's copy: one shape for memo and every CRM CLI. Money is a decimal
17
24
  * string in its currency, both `null` when no amount is expected.
@@ -89,6 +96,11 @@ export declare const deal: v.StrictObjectSchema<{
89
96
  readonly activities: v.OptionalSchema<v.ArraySchema<v.GenericSchema<DealActivity>, undefined>, undefined>;
90
97
  /** `show` of a CRM copy: the newest recorded meetings and calls of its people, in its account's scope. */
91
98
  readonly meetings: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./recorded-meeting.js").RecordedMeeting>, undefined>, undefined>;
99
+ /**
100
+ * `show` of a CRM copy: every stage it entered, oldest first. Once the CRM's own history names any, it alone is
101
+ * listed, from as far back as it was read; the copy's changes between syncs are left out.
102
+ */
103
+ readonly stage_history: v.OptionalSchema<v.ArraySchema<v.GenericSchema<DealStageEntry>, undefined>, undefined>;
92
104
  readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
93
105
  }, undefined>;
94
106
  /** A lead (`lead:<id>`): a deal's shape, in a lead pipeline. */
@@ -165,8 +177,49 @@ export declare const lead: v.StrictObjectSchema<{
165
177
  readonly activities: v.OptionalSchema<v.ArraySchema<v.GenericSchema<DealActivity>, undefined>, undefined>;
166
178
  /** `show` of a CRM copy: the newest recorded meetings and calls of its people, in its account's scope. */
167
179
  readonly meetings: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./recorded-meeting.js").RecordedMeeting>, undefined>, undefined>;
180
+ /**
181
+ * `show` of a CRM copy: every stage it entered, oldest first. Once the CRM's own history names any, it alone is
182
+ * listed, from as far back as it was read; the copy's changes between syncs are left out.
183
+ */
184
+ readonly stage_history: v.OptionalSchema<v.ArraySchema<v.GenericSchema<DealStageEntry>, undefined>, undefined>;
168
185
  readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
169
186
  }, undefined>;
187
+ /** `pipelines show`: the rows made in the window, by their CRM assignee. */
188
+ export interface PipelineOwner {
189
+ assignee: string | null;
190
+ name: string | null;
191
+ open: number;
192
+ won: number;
193
+ lost: number;
194
+ win_rate: number | null;
195
+ }
196
+ export interface PipelineClosed {
197
+ won: number;
198
+ lost: number;
199
+ win_rate: number | null;
200
+ won_amounts: {
201
+ amount: string;
202
+ currency: string;
203
+ items: number;
204
+ }[];
205
+ }
206
+ /** One stage in a pipeline's answer, typed by name for the same reason as `activity`. */
207
+ export interface PipelineStageAnswer {
208
+ name: string;
209
+ position: number;
210
+ outcome: "open" | "won" | "lost";
211
+ external_id: string | null;
212
+ open: number;
213
+ reached?: number;
214
+ conversion?: number | null;
215
+ items?: number;
216
+ amounts?: {
217
+ amount: string;
218
+ currency: string;
219
+ items: number;
220
+ }[];
221
+ median_days?: number | null;
222
+ }
170
223
  /** A pipeline (`pipeline:<id>`) with its stages in order; `pipelines show` adds the funnel. */
171
224
  export declare const pipeline: v.StrictObjectSchema<{
172
225
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -178,25 +231,9 @@ export declare const pipeline: v.StrictObjectSchema<{
178
231
  readonly account: v.StringSchema<undefined>;
179
232
  }, undefined>, undefined>;
180
233
  readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
181
- readonly stages: v.ArraySchema<v.StrictObjectSchema<{
182
- readonly name: v.StringSchema<undefined>;
183
- readonly position: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
184
- readonly outcome: v.PicklistSchema<["open", "won", "lost"], undefined>;
185
- readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
186
- /** Open deals or leads in it now. */
187
- readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
188
- /** With a funnel: rows that got this far, and the share of them that reached the next stage. */
189
- readonly reached: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
190
- readonly conversion: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
191
- /** With a funnel: rows standing in it now, and their sum per currency, never converted. */
192
- readonly items: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
193
- readonly amounts: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
194
- readonly amount: v.StringSchema<undefined>;
195
- readonly currency: v.StringSchema<undefined>;
196
- readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
197
- }, undefined>, undefined>, undefined>;
198
- }, undefined>, undefined>;
234
+ readonly stages: v.ArraySchema<v.GenericSchema<PipelineStageAnswer>, undefined>;
199
235
  readonly created_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
236
+ /** `show`: the rows made in the window. */
200
237
  readonly totals: v.OptionalSchema<v.StrictObjectSchema<{
201
238
  readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
202
239
  readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -204,29 +241,39 @@ export declare const pipeline: v.StrictObjectSchema<{
204
241
  readonly lost: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
205
242
  readonly win_rate: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
206
243
  }, undefined>, undefined>;
244
+ readonly window: v.OptionalSchema<v.StrictObjectSchema<{
245
+ readonly since: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
246
+ readonly until: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
247
+ }, undefined>, undefined>;
207
248
  readonly since: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, undefined>;
208
- readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
209
- }, undefined>;
210
- /** One stage of a pipeline, with the pipeline it is in: what `stages list` answers. */
211
- export declare const stage: v.StrictObjectSchema<{
212
- readonly name: v.StringSchema<undefined>;
213
- readonly position: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
214
- readonly outcome: v.PicklistSchema<["open", "won", "lost"], undefined>;
215
- readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
216
- /** Open deals or leads in it now. */
217
- readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
218
- /** With a funnel: rows that got this far, and the share of them that reached the next stage. */
219
- readonly reached: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
220
- readonly conversion: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
221
- /** With a funnel: rows standing in it now, and their sum per currency, never converted. */
222
- readonly items: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
223
- readonly amounts: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
224
- readonly amount: v.StringSchema<undefined>;
225
- readonly currency: v.StringSchema<undefined>;
249
+ /** `show`: rows closed on a day in the window, in the owner's zone. */
250
+ readonly closed: v.OptionalSchema<v.GenericSchema<PipelineClosed>, undefined>;
251
+ /** `show`: days from made to won, of the rows won in the window. */
252
+ readonly cycle: v.OptionalSchema<v.StrictObjectSchema<{
253
+ readonly median_days: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
254
+ readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
255
+ }, undefined>, undefined>;
256
+ readonly owners: v.OptionalSchema<v.ArraySchema<v.GenericSchema<PipelineOwner>, undefined>, undefined>;
257
+ readonly lost_reasons: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
258
+ readonly reason: v.StringSchema<undefined>;
226
259
  readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
227
260
  }, undefined>, undefined>, undefined>;
228
- readonly pipeline: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
229
- readonly pipeline_name: v.StringSchema<undefined>;
230
- readonly kind: v.PicklistSchema<["deal", "lead"], undefined>;
261
+ /** `show`: rows whose stages came from the CRM's own history, and from the copy's diffs. */
262
+ readonly history: v.OptionalSchema<v.StrictObjectSchema<{
263
+ readonly exact: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
264
+ readonly copy: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
265
+ }, undefined>, undefined>;
231
266
  readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
232
267
  }, undefined>;
268
+ /** One stage of a pipeline, with the pipeline it is in: what `stages list` answers. */
269
+ export interface StageAnswer extends PipelineStageAnswer {
270
+ pipeline: string;
271
+ pipeline_name: string;
272
+ kind: "deal" | "lead";
273
+ stage_task?: {
274
+ title: string;
275
+ due_days: number;
276
+ } | null;
277
+ untrusted?: string[];
278
+ }
279
+ export declare const stage: v.GenericSchema<StageAnswer>;
@@ -21,6 +21,12 @@ const activity = v.strictObject({
21
21
  created_at: time,
22
22
  updated_at: time,
23
23
  });
24
+ const stageEntry = v.strictObject({
25
+ from: nullableText,
26
+ to: text,
27
+ at: time,
28
+ exact: v.boolean(),
29
+ });
24
30
  /**
25
31
  * A deal (`deal:<id>`), the owner's own or a CRM's copy: one shape for memo and every CRM CLI. Money is a decimal
26
32
  * string in its currency, both `null` when no amount is expected.
@@ -83,10 +89,31 @@ export const deal = v.strictObject({
83
89
  activities: v.optional(v.array(activity)),
84
90
  /** `show` of a CRM copy: the newest recorded meetings and calls of its people, in its account's scope. */
85
91
  meetings: v.optional(v.array(recordedMeeting)),
92
+ /**
93
+ * `show` of a CRM copy: every stage it entered, oldest first. Once the CRM's own history names any, it alone is
94
+ * listed, from as far back as it was read; the copy's changes between syncs are left out.
95
+ */
96
+ stage_history: v.optional(v.array(stageEntry)),
86
97
  untrusted,
87
98
  });
88
99
  /** A lead (`lead:<id>`): a deal's shape, in a lead pipeline. */
89
100
  export const lead = deal;
101
+ const amount = v.strictObject({ amount: text, currency: text, items: count });
102
+ const winRate = v.nullable(v.number());
103
+ const pipelineOwner = v.strictObject({
104
+ assignee: nullableText,
105
+ name: nullableText,
106
+ open: count,
107
+ won: count,
108
+ lost: count,
109
+ win_rate: winRate,
110
+ });
111
+ const pipelineClosed = v.strictObject({
112
+ won: count,
113
+ lost: count,
114
+ win_rate: winRate,
115
+ won_amounts: v.array(amount),
116
+ });
90
117
  const pipelineStage = v.strictObject({
91
118
  name: text,
92
119
  position: count,
@@ -99,8 +126,11 @@ const pipelineStage = v.strictObject({
99
126
  conversion: v.optional(v.nullable(v.number())),
100
127
  /** With a funnel: rows standing in it now, and their sum per currency, never converted. */
101
128
  items: v.optional(count),
102
- amounts: v.optional(v.array(v.strictObject({ amount: text, currency: text, items: count }))),
129
+ amounts: v.optional(v.array(amount)),
130
+ /** With a funnel: the median days a row of the window stayed in it before it moved on. */
131
+ median_days: v.optional(v.nullable(v.number())),
103
132
  });
133
+ const pipelineStageAnswer = pipelineStage;
104
134
  /** A pipeline (`pipeline:<id>`) with its stages in order; `pipelines show` adds the funnel. */
105
135
  export const pipeline = v.strictObject({
106
136
  id,
@@ -109,17 +139,28 @@ export const pipeline = v.strictObject({
109
139
  kind: v.picklist(["deal", "lead"]),
110
140
  account: crmAccount,
111
141
  external_id: nullableText,
112
- stages: v.array(pipelineStage),
142
+ stages: v.array(pipelineStageAnswer),
113
143
  created_at: time,
114
- totals: v.optional(v.strictObject({ items: count, open: count, won: count, lost: count, win_rate: v.nullable(v.number()) })),
144
+ /** `show`: the rows made in the window. */
145
+ totals: v.optional(v.strictObject({ items: count, open: count, won: count, lost: count, win_rate: winRate })),
146
+ window: v.optional(v.strictObject({ since: v.nullable(time), until: v.nullable(time) })),
115
147
  since: v.optional(day),
148
+ /** `show`: rows closed on a day in the window, in the owner's zone. */
149
+ closed: v.optional(pipelineClosed),
150
+ /** `show`: days from made to won, of the rows won in the window. */
151
+ cycle: v.optional(v.strictObject({ median_days: v.nullable(v.number()), items: count })),
152
+ owners: v.optional(v.array(pipelineOwner)),
153
+ lost_reasons: v.optional(v.array(v.strictObject({ reason: text, items: count }))),
154
+ /** `show`: rows whose stages came from the CRM's own history, and from the copy's diffs. */
155
+ history: v.optional(v.strictObject({ exact: count, copy: count })),
116
156
  untrusted,
117
157
  });
118
- /** One stage of a pipeline, with the pipeline it is in: what `stages list` answers. */
119
158
  export const stage = v.strictObject({
120
159
  ...pipelineStage.entries,
121
160
  pipeline: reference,
122
161
  pipeline_name: text,
123
162
  kind: v.picklist(["deal", "lead"]),
163
+ /** A CRM's stage: the task its `stage-tasks` rule opens when a row enters it, or `null`. */
164
+ stage_task: v.optional(v.nullable(v.strictObject({ title: text, due_days: count }))),
124
165
  untrusted,
125
166
  });
@@ -333,6 +333,7 @@ export declare const ENTITIES: {
333
333
  readonly updated_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
334
334
  readonly activities: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./deal.js").DealActivity>, undefined>, undefined>;
335
335
  readonly meetings: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./recorded-meeting.js").RecordedMeeting>, undefined>, undefined>;
336
+ readonly stage_history: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./deal.js").DealStageEntry>, undefined>, undefined>;
336
337
  readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
337
338
  }, undefined>;
338
339
  readonly lead: v.StrictObjectSchema<{
@@ -396,6 +397,7 @@ export declare const ENTITIES: {
396
397
  readonly updated_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
397
398
  readonly activities: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./deal.js").DealActivity>, undefined>, undefined>;
398
399
  readonly meetings: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./recorded-meeting.js").RecordedMeeting>, undefined>, undefined>;
400
+ readonly stage_history: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./deal.js").DealStageEntry>, undefined>, undefined>;
399
401
  readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
400
402
  }, undefined>;
401
403
  readonly pipeline: v.StrictObjectSchema<{
@@ -408,21 +410,7 @@ export declare const ENTITIES: {
408
410
  readonly account: v.StringSchema<undefined>;
409
411
  }, undefined>, undefined>;
410
412
  readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
411
- readonly stages: v.ArraySchema<v.StrictObjectSchema<{
412
- readonly name: v.StringSchema<undefined>;
413
- readonly position: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
414
- readonly outcome: v.PicklistSchema<["open", "won", "lost"], undefined>;
415
- readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
416
- readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
417
- readonly reached: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
418
- readonly conversion: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
419
- readonly items: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
420
- readonly amounts: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
421
- readonly amount: v.StringSchema<undefined>;
422
- readonly currency: v.StringSchema<undefined>;
423
- readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
424
- }, undefined>, undefined>, undefined>;
425
- }, undefined>, undefined>;
413
+ readonly stages: v.ArraySchema<v.GenericSchema<import("./deal.js").PipelineStageAnswer>, undefined>;
426
414
  readonly created_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
427
415
  readonly totals: v.OptionalSchema<v.StrictObjectSchema<{
428
416
  readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -431,28 +419,28 @@ export declare const ENTITIES: {
431
419
  readonly lost: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
432
420
  readonly win_rate: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
433
421
  }, undefined>, undefined>;
422
+ readonly window: v.OptionalSchema<v.StrictObjectSchema<{
423
+ readonly since: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
424
+ readonly until: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
425
+ }, undefined>, undefined>;
434
426
  readonly since: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, undefined>;
435
- readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
436
- }, undefined>;
437
- readonly stage: v.StrictObjectSchema<{
438
- readonly name: v.StringSchema<undefined>;
439
- readonly position: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
440
- readonly outcome: v.PicklistSchema<["open", "won", "lost"], undefined>;
441
- readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
442
- readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
443
- readonly reached: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
444
- readonly conversion: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
445
- readonly items: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
446
- readonly amounts: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
447
- readonly amount: v.StringSchema<undefined>;
448
- readonly currency: v.StringSchema<undefined>;
427
+ readonly closed: v.OptionalSchema<v.GenericSchema<import("./deal.js").PipelineClosed>, undefined>;
428
+ readonly cycle: v.OptionalSchema<v.StrictObjectSchema<{
429
+ readonly median_days: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
430
+ readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
431
+ }, undefined>, undefined>;
432
+ readonly owners: v.OptionalSchema<v.ArraySchema<v.GenericSchema<import("./deal.js").PipelineOwner>, undefined>, undefined>;
433
+ readonly lost_reasons: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
434
+ readonly reason: v.StringSchema<undefined>;
449
435
  readonly items: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
450
436
  }, undefined>, undefined>, undefined>;
451
- readonly pipeline: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
452
- readonly pipeline_name: v.StringSchema<undefined>;
453
- readonly kind: v.PicklistSchema<["deal", "lead"], undefined>;
437
+ readonly history: v.OptionalSchema<v.StrictObjectSchema<{
438
+ readonly exact: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
439
+ readonly copy: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
440
+ }, undefined>, undefined>;
454
441
  readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
455
442
  }, undefined>;
443
+ readonly stage: v.GenericSchema<import("./deal.js").StageAnswer>;
456
444
  readonly message: v.StrictObjectSchema<{
457
445
  readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
458
446
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -461,6 +461,7 @@ const OTHERS = [
461
461
  validation("field.not-filterable", "the CRM cannot filter a list by that custom field"),
462
462
  validation("query.bad-value", "a term's value is not the kind its field takes, such as an id or a number"),
463
463
  validation("crm.record-field", "a contact's or company's field is not valid"),
464
+ validation("crm.owner-unknown", "owner: names no CRM user: me without a known sign-in user, or not a user id"),
464
465
  validation("crm.write-unsupported", "the CRM does not take this write, or does not recognise a repeated one"),
465
466
  validation("crm.unlisted-held", "a list of every id would mark most of a kind deleted; nothing was, until --rescan"),
466
467
  validation("crm.narrowing-held", "the default scope mine would mark most of a kind's stored rows deleted; none is, until the owner sets the scope"),
@@ -548,6 +549,7 @@ const OTHERS = [
548
549
  "the owner rejected linking these people on this evidence; only a new signal or identity proposes them again",
549
550
  ],
550
551
  validation("identity.same", "the two identities are one person already"),
552
+ validation("identity.agent-unnamed", "an agent's link names the agent, and never as the owner"),
551
553
  validation("identity.not-shared", "only a match on a shared mailbox can say the mailbox is a company's"),
552
554
  ["organization.not-found", "not_found", "no stored organization has that id"],
553
555
  validation("organization.unnamed", "a free mailbox names no company; name the organization or the company"),