@opencxh/domain 1.277.0 → 1.279.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.
@@ -39,6 +39,11 @@ export interface Product {
39
39
  ledgerCategoryKey?: string;
40
40
  /** References to this product elsewhere (`moneybird:412`). A reference, never a copy. */
41
41
  externalIds?: string[];
42
+ /**
43
+ * Hours booked on this `WorkType.key` are invoiced as this product. Here and not on the work
44
+ * type: time must not know sales, and several products may share one type (junior/senior).
45
+ */
46
+ workTypeKey?: string;
42
47
  /** See {@link FIXED_UNITS}. Drives the form and the word after the quantity. */
43
48
  unitKey: string;
44
49
  /** Key into the organisation's VAT table, never the percentage itself. */
@@ -1,5 +1,8 @@
1
1
  import { PostalAddress } from '../organization/types';
2
+ import { LifecycleStage } from '../contact/lifecycle';
2
3
  import { OwnerScope } from '../scope/types';
4
+ /** Same meaning as {@link ContactOrigin}: `shadow` is a lazily cached hit, a landed row is `own`. */
5
+ export type CompanyOrigin = "own" | "shadow";
3
6
  /** Where a company row came from. `local` is a row somebody created by hand. */
4
7
  export interface CompanySource {
5
8
  providerId: string;
@@ -40,6 +43,11 @@ export interface Company {
40
43
  externalIds: string[];
41
44
  ownerScope: OwnerScope;
42
45
  source: CompanySource;
46
+ origin?: CompanyOrigin;
47
+ /** Where the organisation stands with us; independent of its contacts' own stages. */
48
+ lifecycleStage?: LifecycleStage;
49
+ /** The group this company belongs to. One level up per row; a cycle is refused on write. */
50
+ parentCompanyId?: string;
43
51
  /**
44
52
  * Where the company sits. Needed by anything that puts this company on paper — a quote's
45
53
  * recipient block is the first, and the issue gate refuses a document with a hole in it.
@@ -1,3 +1,6 @@
1
1
  export * from './endpoints';
2
+ export * from './lifecycle';
3
+ export * from './name';
2
4
  export * from './provider';
5
+ export * from './segment';
3
6
  export * from './types';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Where a person stands with us. `lead` has not been qualified yet; qualifying (a deal is made)
3
+ * moves it to `opportunity`. `customer` and `former` are set by hand or by a rule.
4
+ */
5
+ export declare const LIFECYCLE_STAGES: readonly ["lead", "opportunity", "customer", "former"];
6
+ export type LifecycleStage = (typeof LIFECYCLE_STAGES)[number];
7
+ /** How far a lead is worked; only meaningful while the stage is `lead`. */
8
+ export declare const LEAD_STATUSES: readonly ["new", "working", "unqualified"];
9
+ export type LeadStatus = (typeof LEAD_STATUSES)[number];
@@ -0,0 +1,3 @@
1
+ import { Contact } from './types';
2
+ /** "First Last", trimmed; empty when the row has neither. */
3
+ export declare function contactName(contact: Pick<Contact, "firstName" | "lastName">): string;
@@ -0,0 +1,32 @@
1
+ import { SavedView, SavedViewSort } from '../saved-view/types';
2
+ /**
3
+ * A crm segment: a {@link SavedView} over contacts or companies. It stores the question, never
4
+ * the rows — whoever matches later is in it. One filter shape for both lists; `SEGMENT_FILTER_KEYS`
5
+ * says which keys a kind reads, and the server drops the rest.
6
+ */
7
+ export type SegmentKind = "contact" | "company";
8
+ /** Multi-value filters: empty or absent = no filter on that axis. */
9
+ export declare const SEGMENT_LIST_FILTERS: readonly ["stages", "leadStatuses", "sources", "scopes", "cities", "parentCompanyIds"];
10
+ export type SegmentListFilter = (typeof SEGMENT_LIST_FILTERS)[number];
11
+ /** Yes/no filters that need another store to answer: open deals in work, people at a company. */
12
+ export declare const SEGMENT_PRESENCE_FILTERS: readonly ["openDeal", "hasContacts"];
13
+ export type SegmentPresenceFilter = (typeof SEGMENT_PRESENCE_FILTERS)[number];
14
+ export type SegmentFilters = {
15
+ search?: string;
16
+ /** Created in the last N days; relative, so a saved segment stays current. */
17
+ createdWithinDays?: number;
18
+ /** Select custom fields: field key → accepted values. */
19
+ fields?: Record<string, string[]>;
20
+ } & Partial<Record<SegmentListFilter, string[]>> & Partial<Record<SegmentPresenceFilter, "yes" | "no">>;
21
+ /** Which filters each list offers. `sources` holds provider ids (`local`, `hubspot`). */
22
+ export declare const SEGMENT_FILTER_KEYS: Record<SegmentKind, readonly string[]>;
23
+ export declare const SEGMENT_SORT_FIELDS: readonly ["updatedAt", "createdAt", "name"];
24
+ export type SegmentSortField = (typeof SEGMENT_SORT_FIELDS)[number];
25
+ export type SegmentSort = SavedViewSort<SegmentSortField>;
26
+ export declare const SEGMENT_LAYOUTS: readonly ["list"];
27
+ export type SegmentLayout = (typeof SEGMENT_LAYOUTS)[number];
28
+ export type CrmSegment = SavedView<SegmentFilters, SegmentLayout, SegmentSortField> & {
29
+ kind: SegmentKind;
30
+ };
31
+ /** True when a filter narrows anything; an empty segment is the plain list. */
32
+ export declare function segmentIsEmpty(filters: SegmentFilters): boolean;
@@ -1,5 +1,6 @@
1
1
  import { CommunicationScheme } from '../../platform/communication';
2
2
  import { OwnerScope } from '../scope/types';
3
+ import { LeadStatus, LifecycleStage } from './lifecycle';
3
4
  export interface ContactEndpoint {
4
5
  scheme: CommunicationScheme;
5
6
  resource: string;
@@ -69,6 +70,11 @@ export interface Contact {
69
70
  */
70
71
  locale?: string;
71
72
  origin?: ContactOrigin;
73
+ jobTitle?: string;
74
+ lifecycleStage?: LifecycleStage;
75
+ leadStatus?: LeadStatus;
76
+ /** When a deal was first made for this person (`POST /contact/:id/qualify`). */
77
+ qualifiedAt?: number;
72
78
  /** When a shadow row last saw its source. There is no refresh job; touching refreshes. */
73
79
  syncedAt?: number;
74
80
  }
@@ -0,0 +1,20 @@
1
+ import { TimeEntry } from './types';
2
+ /** Booked hours that become one invoice line: one work type on one subject. */
3
+ export interface BillableTimeGroup {
4
+ /** `WorkType.key`; absent = booked without a type, which no product can carry. */
5
+ workType?: string;
6
+ scopeKey?: string;
7
+ scopeLabel?: string;
8
+ seconds: number;
9
+ /** Hours, two decimals — what goes on the line as `quantity`. */
10
+ hours: number;
11
+ entryIds: string[];
12
+ /** Epoch ms of the first and last entry, for the line's description. */
13
+ from: number;
14
+ to: number;
15
+ }
16
+ /**
17
+ * Group billable entries per work type × subject, in the order they were first booked.
18
+ * `durationSeconds` is the booked duration, so rounding has already been applied per entry.
19
+ */
20
+ export declare function billableTimeGroups(entries: readonly TimeEntry[]): BillableTimeGroup[];
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
+ export * from './billing';
1
2
  export * from './duration';
2
3
  export * from './types';
3
4
  export * from './work-type';
@@ -69,6 +69,11 @@ export interface TimeEntry {
69
69
  workType?: string;
70
70
  note?: string;
71
71
  source: TimeEntrySource;
72
+ /**
73
+ * The invoice (a sales transaction id) this entry is on, draft included. Set by sales only;
74
+ * while set, the entry cannot be edited or deleted — that is what stops billing it twice.
75
+ */
76
+ invoicedTransactionId?: string;
72
77
  createdAt?: number;
73
78
  updatedAt?: number;
74
79
  }
@@ -177,6 +177,11 @@ export interface TransactionLine {
177
177
  * booked against, not what the customer reads.
178
178
  */
179
179
  dealItemId?: string;
180
+ /**
181
+ * The time entries this line bills. Sales stamps exactly this set onto them on every save, so
182
+ * the line — not the entry — is the source of truth. Never copied to a new document.
183
+ */
184
+ timeEntryIds?: string[];
180
185
  /**
181
186
  * An option: priced and shown, but **not** in the total.
182
187
  *