@baack-software/baack-ts-crm 0.0.0-stage → 0.0.2
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.
- package/LICENSE +201 -0
- package/README.md +74 -2
- package/dist/account.d.ts +36 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +48 -0
- package/dist/account.js.map +1 -0
- package/dist/backend.d.ts +76 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +233 -0
- package/dist/backend.js.map +1 -0
- package/dist/crm-client.d.ts +122 -0
- package/dist/crm-client.d.ts.map +1 -0
- package/dist/crm-client.js +168 -0
- package/dist/crm-client.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +33 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/invoices.d.ts +46 -0
- package/dist/invoices.d.ts.map +1 -0
- package/dist/invoices.js +137 -0
- package/dist/invoices.js.map +1 -0
- package/dist/leads.d.ts +29 -0
- package/dist/leads.d.ts.map +1 -0
- package/dist/leads.js +56 -0
- package/dist/leads.js.map +1 -0
- package/dist/mock/index.d.ts +43 -0
- package/dist/mock/index.d.ts.map +1 -0
- package/dist/mock/index.js +303 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/money.d.ts +29 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +82 -0
- package/dist/money.js.map +1 -0
- package/dist/period.d.ts +17 -0
- package/dist/period.d.ts.map +1 -0
- package/dist/period.js +23 -0
- package/dist/period.js.map +1 -0
- package/dist/pipeline.d.ts +30 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +40 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/react/Charts.d.ts +19 -0
- package/dist/react/Charts.d.ts.map +1 -0
- package/dist/react/Charts.js +38 -0
- package/dist/react/Charts.js.map +1 -0
- package/dist/react/CompanyAccountView.d.ts +21 -0
- package/dist/react/CompanyAccountView.d.ts.map +1 -0
- package/dist/react/CompanyAccountView.js +27 -0
- package/dist/react/CompanyAccountView.js.map +1 -0
- package/dist/react/DashboardCards.d.ts +32 -0
- package/dist/react/DashboardCards.d.ts.map +1 -0
- package/dist/react/DashboardCards.js +38 -0
- package/dist/react/DashboardCards.js.map +1 -0
- package/dist/react/DealsBoard.d.ts +30 -0
- package/dist/react/DealsBoard.d.ts.map +1 -0
- package/dist/react/DealsBoard.js +33 -0
- package/dist/react/DealsBoard.js.map +1 -0
- package/dist/react/Details.d.ts +52 -0
- package/dist/react/Details.d.ts.map +1 -0
- package/dist/react/Details.js +111 -0
- package/dist/react/Details.js.map +1 -0
- package/dist/react/Forms.d.ts +59 -0
- package/dist/react/Forms.d.ts.map +1 -0
- package/dist/react/Forms.js +204 -0
- package/dist/react/Forms.js.map +1 -0
- package/dist/react/LeadsTable.d.ts +22 -0
- package/dist/react/LeadsTable.d.ts.map +1 -0
- package/dist/react/LeadsTable.js +79 -0
- package/dist/react/LeadsTable.js.map +1 -0
- package/dist/react/Sales.d.ts +49 -0
- package/dist/react/Sales.d.ts.map +1 -0
- package/dist/react/Sales.js +186 -0
- package/dist/react/Sales.js.map +1 -0
- package/dist/react/SidePanel.d.ts +21 -0
- package/dist/react/SidePanel.d.ts.map +1 -0
- package/dist/react/SidePanel.js +37 -0
- package/dist/react/SidePanel.js.map +1 -0
- package/dist/react/format.d.ts +28 -0
- package/dist/react/format.d.ts.map +1 -0
- package/dist/react/format.js +30 -0
- package/dist/react/format.js.map +1 -0
- package/dist/react/index.d.ts +14 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +14 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/parts.d.ts +45 -0
- package/dist/react/parts.d.ts.map +1 -0
- package/dist/react/parts.js +59 -0
- package/dist/react/parts.js.map +1 -0
- package/dist/react/text.d.ts +145 -0
- package/dist/react/text.d.ts.map +1 -0
- package/dist/react/text.js +142 -0
- package/dist/react/text.js.map +1 -0
- package/dist/react/ui/alert.d.ts +11 -0
- package/dist/react/ui/alert.d.ts.map +1 -0
- package/dist/react/ui/alert.js +29 -0
- package/dist/react/ui/alert.js.map +1 -0
- package/dist/react/ui/badge.d.ts +10 -0
- package/dist/react/ui/badge.d.ts.map +1 -0
- package/dist/react/ui/badge.js +26 -0
- package/dist/react/ui/badge.js.map +1 -0
- package/dist/react/ui/button.d.ts +11 -0
- package/dist/react/ui/button.d.ts.map +1 -0
- package/dist/react/ui/button.js +37 -0
- package/dist/react/ui/button.js.map +1 -0
- package/dist/react/ui/card.d.ts +12 -0
- package/dist/react/ui/card.d.ts.map +1 -0
- package/dist/react/ui/card.js +26 -0
- package/dist/react/ui/card.js.map +1 -0
- package/dist/react/ui/chart.d.ts +45 -0
- package/dist/react/ui/chart.d.ts.map +1 -0
- package/dist/react/ui/chart.js +116 -0
- package/dist/react/ui/chart.js.map +1 -0
- package/dist/react/ui/input.d.ts +4 -0
- package/dist/react/ui/input.d.ts.map +1 -0
- package/dist/react/ui/input.js +8 -0
- package/dist/react/ui/input.js.map +1 -0
- package/dist/react/ui/label.d.ts +5 -0
- package/dist/react/ui/label.d.ts.map +1 -0
- package/dist/react/ui/label.js +10 -0
- package/dist/react/ui/label.js.map +1 -0
- package/dist/react/ui/progress.d.ts +5 -0
- package/dist/react/ui/progress.d.ts.map +1 -0
- package/dist/react/ui/progress.js +10 -0
- package/dist/react/ui/progress.js.map +1 -0
- package/dist/react/ui/select.d.ts +16 -0
- package/dist/react/ui/select.d.ts.map +1 -0
- package/dist/react/ui/select.js +37 -0
- package/dist/react/ui/select.js.map +1 -0
- package/dist/react/ui/separator.d.ts +5 -0
- package/dist/react/ui/separator.d.ts.map +1 -0
- package/dist/react/ui/separator.js +10 -0
- package/dist/react/ui/separator.js.map +1 -0
- package/dist/react/ui/sheet.d.ts +15 -0
- package/dist/react/ui/sheet.d.ts.map +1 -0
- package/dist/react/ui/sheet.js +38 -0
- package/dist/react/ui/sheet.js.map +1 -0
- package/dist/react/ui/skeleton.d.ts +3 -0
- package/dist/react/ui/skeleton.d.ts.map +1 -0
- package/dist/react/ui/skeleton.js +7 -0
- package/dist/react/ui/skeleton.js.map +1 -0
- package/dist/react/ui/table.d.ts +11 -0
- package/dist/react/ui/table.d.ts.map +1 -0
- package/dist/react/ui/table.js +29 -0
- package/dist/react/ui/table.js.map +1 -0
- package/dist/react/ui/tabs.d.ts +12 -0
- package/dist/react/ui/tabs.d.ts.map +1 -0
- package/dist/react/ui/tabs.js +31 -0
- package/dist/react/ui/tabs.js.map +1 -0
- package/dist/react/views.d.ts +60 -0
- package/dist/react/views.d.ts.map +1 -0
- package/dist/react/views.js +172 -0
- package/dist/react/views.js.map +1 -0
- package/dist/sales.d.ts +57 -0
- package/dist/sales.d.ts.map +1 -0
- package/dist/sales.js +64 -0
- package/dist/sales.js.map +1 -0
- package/dist/store.d.ts +140 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +244 -0
- package/dist/store.js.map +1 -0
- package/dist/target.d.ts +21 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +36 -0
- package/dist/target.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +100 -4
- package/src/account.ts +79 -0
- package/src/backend.ts +371 -0
- package/src/crm-client.ts +250 -0
- package/src/errors.ts +34 -0
- package/src/index.ts +12 -0
- package/src/invoices.ts +157 -0
- package/src/leads.ts +78 -0
- package/src/mock/index.ts +398 -0
- package/src/money.ts +104 -0
- package/src/period.ts +32 -0
- package/src/pipeline.ts +61 -0
- package/src/react/Charts.tsx +143 -0
- package/src/react/CompanyAccountView.tsx +198 -0
- package/src/react/DashboardCards.tsx +171 -0
- package/src/react/DealsBoard.tsx +177 -0
- package/src/react/Details.tsx +293 -0
- package/src/react/Forms.tsx +619 -0
- package/src/react/LeadsTable.tsx +234 -0
- package/src/react/Sales.tsx +539 -0
- package/src/react/SidePanel.tsx +95 -0
- package/src/react/format.ts +53 -0
- package/src/react/index.ts +13 -0
- package/src/react/parts.tsx +131 -0
- package/src/react/text.ts +144 -0
- package/src/react/ui/README.md +6 -0
- package/src/react/ui/alert.tsx +75 -0
- package/src/react/ui/badge.tsx +48 -0
- package/src/react/ui/button.tsx +66 -0
- package/src/react/ui/card.tsx +102 -0
- package/src/react/ui/chart.tsx +304 -0
- package/src/react/ui/input.tsx +18 -0
- package/src/react/ui/label.tsx +23 -0
- package/src/react/ui/progress.tsx +30 -0
- package/src/react/ui/select.tsx +189 -0
- package/src/react/ui/separator.tsx +27 -0
- package/src/react/ui/sheet.tsx +145 -0
- package/src/react/ui/skeleton.tsx +13 -0
- package/src/react/ui/table.tsx +113 -0
- package/src/react/ui/tabs.tsx +89 -0
- package/src/react/views.tsx +443 -0
- package/src/sales.ts +120 -0
- package/src/store.ts +419 -0
- package/src/target.ts +51 -0
- package/src/types.ts +202 -0
package/dist/store.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { urnOf } from '@baack-software/baack-ts-tasks';
|
|
2
|
+
import { companyAccount } from "./account.js";
|
|
3
|
+
import { CrmUnavailableError } from "./errors.js";
|
|
4
|
+
import { leadsBySource } from "./leads.js";
|
|
5
|
+
import { addMoney } from "./money.js";
|
|
6
|
+
import { inRange, periodChange, previousRange } from "./period.js";
|
|
7
|
+
import { dealCompany, dealOutcome, pipelineByStage } from "./pipeline.js";
|
|
8
|
+
import { paymentsByDay, paymentsReceived } from "./invoices.js";
|
|
9
|
+
import { salesSummary } from "./sales.js";
|
|
10
|
+
import { salesTarget } from "./target.js";
|
|
11
|
+
import { CRM_CONCEPTS, } from "./types.js";
|
|
12
|
+
const idle = Object.fromEntries(CRM_CONCEPTS.map((concept) => [concept, { status: 'idle' }]));
|
|
13
|
+
const EMPTY = {
|
|
14
|
+
status: 'idle',
|
|
15
|
+
concepts: idle,
|
|
16
|
+
leads: [],
|
|
17
|
+
deals: [],
|
|
18
|
+
pipelines: [],
|
|
19
|
+
invoices: [],
|
|
20
|
+
remittances: [],
|
|
21
|
+
companies: [],
|
|
22
|
+
saving: new Set(),
|
|
23
|
+
};
|
|
24
|
+
let pendingCount = 0;
|
|
25
|
+
/**
|
|
26
|
+
* Holds a company's CRM records for a UI: loads every concept, applies changes straight away and rolls them back if
|
|
27
|
+
* the server refuses, and notifies subscribers. `subscribe` and `getState` fit React's `useSyncExternalStore`.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const store = new CrmStore(crm, { owner });
|
|
31
|
+
* store.subscribe(() => render(selectDashboard(store.getState(), lastDays(28))));
|
|
32
|
+
* await store.load();
|
|
33
|
+
* await store.moveDeal(dealUrn, stage);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class CrmStore {
|
|
37
|
+
client;
|
|
38
|
+
options;
|
|
39
|
+
#state = EMPTY;
|
|
40
|
+
#listeners = new Set();
|
|
41
|
+
#disposed = false;
|
|
42
|
+
constructor(client, options) {
|
|
43
|
+
this.client = client;
|
|
44
|
+
this.options = options;
|
|
45
|
+
}
|
|
46
|
+
getState = () => this.#state;
|
|
47
|
+
subscribe = (listener) => {
|
|
48
|
+
this.#listeners.add(listener);
|
|
49
|
+
return () => this.#listeners.delete(listener);
|
|
50
|
+
};
|
|
51
|
+
/** Drops subscribers; answers still arriving are ignored. */
|
|
52
|
+
dispose() {
|
|
53
|
+
this.#disposed = true;
|
|
54
|
+
this.#listeners.clear();
|
|
55
|
+
}
|
|
56
|
+
#set(next) {
|
|
57
|
+
if (this.#disposed)
|
|
58
|
+
return;
|
|
59
|
+
this.#state = { ...this.#state, ...next };
|
|
60
|
+
for (const listener of this.#listeners)
|
|
61
|
+
listener();
|
|
62
|
+
}
|
|
63
|
+
// ==========================================
|
|
64
|
+
// LOADING
|
|
65
|
+
// ==========================================
|
|
66
|
+
/** Loads (or reloads) every concept at once. A concept that fails doesn't stop the others. */
|
|
67
|
+
async load() {
|
|
68
|
+
const owner = urnOf(this.options.owner);
|
|
69
|
+
const loading = Object.fromEntries(CRM_CONCEPTS.map((concept) => [concept, { status: 'loading' }]));
|
|
70
|
+
this.#set({ status: 'loading', concepts: loading });
|
|
71
|
+
await Promise.all(CRM_CONCEPTS.map(async (concept) => {
|
|
72
|
+
try {
|
|
73
|
+
const records = await this.client[concept].list(owner);
|
|
74
|
+
this.#set({ [concept]: records, concepts: { ...this.#state.concepts, [concept]: { status: 'ready' } } });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
const status = error instanceof CrmUnavailableError ? 'unavailable' : 'error';
|
|
78
|
+
this.#set({ concepts: { ...this.#state.concepts, [concept]: { status, error } } });
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
const failed = Object.values(this.#state.concepts).some((state) => state.status === 'error');
|
|
82
|
+
this.#set({ status: failed ? 'error' : 'ready' });
|
|
83
|
+
}
|
|
84
|
+
// ==========================================
|
|
85
|
+
// WRITES
|
|
86
|
+
// ==========================================
|
|
87
|
+
/** Shows `optimistic` at once, runs `write`, then shows what the server stored, or rolls back if it refuses. */
|
|
88
|
+
async #write(urns, optimistic, write, stored) {
|
|
89
|
+
const before = this.#records();
|
|
90
|
+
this.#set({ ...optimistic(before), saving: new Set([...this.#state.saving, ...urns]), writeError: undefined });
|
|
91
|
+
const saved = () => new Set([...this.#state.saving].filter((urn) => !urns.includes(urn)));
|
|
92
|
+
try {
|
|
93
|
+
const result = await write();
|
|
94
|
+
this.#set({ ...stored(this.#records(), result), saving: saved() });
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
this.#set({ ...before, saving: saved(), writeError: error });
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
#records() {
|
|
103
|
+
const { leads, deals, pipelines, invoices, remittances, companies } = this.#state;
|
|
104
|
+
return { leads, deals, pipelines, invoices, remittances, companies };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates a lead, shown at the top straight away. With `companyName`, the prospect's company is made first and linked
|
|
108
|
+
* (see `CrmClient.createLead`).
|
|
109
|
+
*/
|
|
110
|
+
async createLead(input, options = {}) {
|
|
111
|
+
const temporary = `pending-${++pendingCount}`;
|
|
112
|
+
const placeholder = { ...input, urn: temporary, createdTimestamp: '' };
|
|
113
|
+
const { lead } = await this.#write([temporary], ({ leads }) => ({ leads: [placeholder, ...leads] }), () => this.client.createLead(input, options), ({ leads, companies }, result) => ({
|
|
114
|
+
leads: leads.map((candidate) => (candidate.urn === temporary ? result.lead : candidate)),
|
|
115
|
+
...(result.company ? { companies: [...companies, result.company] } : {}),
|
|
116
|
+
}));
|
|
117
|
+
return lead;
|
|
118
|
+
}
|
|
119
|
+
/** Changes a lead. */
|
|
120
|
+
updateLead(lead, changes) {
|
|
121
|
+
const urn = urnOf(lead);
|
|
122
|
+
return this.#write([urn], ({ leads }) => ({ leads: replace(leads, urn, (current) => ({ ...current, ...changes })) }), () => this.client.leads.update(urn, changes), ({ leads }, updated) => ({ leads: replace(leads, urn, () => updated) }));
|
|
123
|
+
}
|
|
124
|
+
/** Qualifies a lead into a deal (see `CrmClient.convertLead`). Shown once the server has made the deal. */
|
|
125
|
+
async convertLead(lead, options) {
|
|
126
|
+
const urn = urnOf(lead);
|
|
127
|
+
const current = this.#state.leads.find((candidate) => candidate.urn === urn);
|
|
128
|
+
if (!current)
|
|
129
|
+
throw new Error(`No lead ${urn} in the store`);
|
|
130
|
+
return this.#write([urn], () => ({}), () => this.client.convertLead(current, options), ({ leads, deals, companies }, result) => ({
|
|
131
|
+
leads: replace(leads, urn, () => result.lead),
|
|
132
|
+
deals: [result.deal, ...deals],
|
|
133
|
+
...(result.company ? { companies: [...companies, result.company] } : {}),
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
/** Moves a deal to a stage, shown at once (see `CrmClient.moveDeal`). */
|
|
137
|
+
moveDeal(deal, stage) {
|
|
138
|
+
const urn = urnOf(deal);
|
|
139
|
+
return this.#write([urn], ({ deals }) => ({ deals: replace(deals, urn, (current) => ({ ...current, workflowStage: { urn: stage.urn } })) }), () => this.client.moveDeal(urn, stage), ({ deals }, moved) => ({ deals: replace(deals, urn, () => moved) }));
|
|
140
|
+
}
|
|
141
|
+
/** Wins, loses or reopens a deal, shown at once (see `CrmClient.setOutcome`). */
|
|
142
|
+
setOutcome(deal, outcome, options = {}) {
|
|
143
|
+
const urn = urnOf(deal);
|
|
144
|
+
return this.#write([urn], ({ deals }) => ({ deals: replace(deals, urn, (current) => ({ ...current, outcome })) }), () => this.client.setOutcome(urn, outcome, options), ({ deals }, stored) => ({ deals: replace(deals, urn, () => stored) }));
|
|
145
|
+
}
|
|
146
|
+
/** Closes a lead as unqualified or reopens it, shown at once (see `CrmClient.setLeadOutcome`). */
|
|
147
|
+
setLeadOutcome(lead, outcome, options = {}) {
|
|
148
|
+
const urn = urnOf(lead);
|
|
149
|
+
return this.#write([urn], ({ leads }) => ({ leads: replace(leads, urn, (current) => ({ ...current, outcome })) }), () => this.client.setLeadOutcome(urn, outcome, options), ({ leads }, stored) => ({ leads: replace(leads, urn, () => stored) }));
|
|
150
|
+
}
|
|
151
|
+
/** Creates a deal, shown on the board straight away. */
|
|
152
|
+
createDeal(input) {
|
|
153
|
+
const temporary = `pending-${++pendingCount}`;
|
|
154
|
+
const placeholder = { ...input, urn: temporary, createdTimestamp: '' };
|
|
155
|
+
return this.#write([temporary], ({ deals }) => ({ deals: [placeholder, ...deals] }), () => this.client.createDeal(input), ({ deals }, made) => ({ deals: deals.map((candidate) => (candidate.urn === temporary ? made : candidate)) }));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates an invoice with its lines, linked to `deal` when given (see `CrmClient.createInvoice`). Shown once the
|
|
159
|
+
* server has made it, as its lines are made one by one.
|
|
160
|
+
*/
|
|
161
|
+
async createInvoice(input, lines = [], options = {}) {
|
|
162
|
+
const { invoice } = await this.#write(options.deal ? [options.deal.urn] : [], () => ({}), () => this.client.createInvoice(input, lines, options), ({ invoices, deals }, result) => ({
|
|
163
|
+
invoices: [result.invoice, ...invoices],
|
|
164
|
+
...(result.deal ? { deals: replace(deals, result.deal.urn, () => result.deal) } : {}),
|
|
165
|
+
}));
|
|
166
|
+
return invoice;
|
|
167
|
+
}
|
|
168
|
+
/** Records a payment or refund against an invoice. */
|
|
169
|
+
recordPayment(input) {
|
|
170
|
+
const temporary = `pending-${++pendingCount}`;
|
|
171
|
+
return this.#write([temporary], ({ remittances }) => ({ remittances: [{ ...input, urn: temporary }, ...remittances] }), () => this.client.recordPayment(input), ({ remittances }, made) => ({
|
|
172
|
+
remittances: remittances.map((candidate) => (candidate.urn === temporary ? made : candidate)),
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function replace(records, urn, change) {
|
|
177
|
+
return records.map((record) => (record.urn === urn ? change(record) : record));
|
|
178
|
+
}
|
|
179
|
+
const compare = (current, previous) => ({
|
|
180
|
+
current,
|
|
181
|
+
previous,
|
|
182
|
+
change: periodChange(current, previous),
|
|
183
|
+
});
|
|
184
|
+
/** The largest currency in a set of totals. */
|
|
185
|
+
export const mainCurrency = (totals) => Object.entries(totals).sort(([, a], [, b]) => b - a)[0]?.[0];
|
|
186
|
+
/** Everything a CRM dashboard shows for a period, compared with the period before. */
|
|
187
|
+
export function selectDashboard(state, range) {
|
|
188
|
+
const before = previousRange(range);
|
|
189
|
+
const { leads, deals, pipelines, remittances } = state;
|
|
190
|
+
const firstWins = new Map();
|
|
191
|
+
let openValue = {};
|
|
192
|
+
let openCount = 0;
|
|
193
|
+
for (const deal of deals) {
|
|
194
|
+
const outcome = dealOutcome(deal);
|
|
195
|
+
if (outcome === 'OPEN') {
|
|
196
|
+
openCount += 1;
|
|
197
|
+
openValue = addMoney(openValue, deal.targetValue);
|
|
198
|
+
}
|
|
199
|
+
const company = dealCompany(deal)?.urn;
|
|
200
|
+
if (outcome === 'WON' && company) {
|
|
201
|
+
const closed = deal.closeTimestamp ?? deal.updatedTimestamp ?? deal.createdTimestamp;
|
|
202
|
+
const known = firstWins.get(company);
|
|
203
|
+
if (!known || closed < known)
|
|
204
|
+
firstWins.set(company, closed);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const count = (records, when, period) => [...records].filter((record) => inRange(when(record), period)).length;
|
|
208
|
+
const wins = [...firstWins.values()];
|
|
209
|
+
const current = paymentsReceived(remittances, range);
|
|
210
|
+
const previous = paymentsReceived(remittances, before);
|
|
211
|
+
const revenueCurrency = mainCurrency(current) ?? mainCurrency(previous);
|
|
212
|
+
return {
|
|
213
|
+
range,
|
|
214
|
+
customers: {
|
|
215
|
+
total: firstWins.size,
|
|
216
|
+
added: compare(count(wins, (when) => when, range), count(wins, (when) => when, before)),
|
|
217
|
+
},
|
|
218
|
+
openDeals: {
|
|
219
|
+
count: openCount,
|
|
220
|
+
value: openValue,
|
|
221
|
+
created: compare(count(deals, (deal) => deal.createdTimestamp, range), count(deals, (deal) => deal.createdTimestamp, before)),
|
|
222
|
+
},
|
|
223
|
+
revenue: {
|
|
224
|
+
current,
|
|
225
|
+
previous,
|
|
226
|
+
currencyCode: revenueCurrency,
|
|
227
|
+
change: revenueCurrency ? periodChange(current[revenueCurrency] ?? 0, previous[revenueCurrency] ?? 0) : undefined,
|
|
228
|
+
},
|
|
229
|
+
revenueByDay: paymentsByDay(remittances, range),
|
|
230
|
+
newLeads: compare(count(leads, (lead) => lead.createdTimestamp, range), count(leads, (lead) => lead.createdTimestamp, before)),
|
|
231
|
+
target: salesTarget(leads, deals, remittances),
|
|
232
|
+
leadsBySource: leadsBySource(leads),
|
|
233
|
+
pipeline: pipelines[0] ? pipelineByStage(deals, pipelines[0]) : [],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/** One customer company's account from the store's records. */
|
|
237
|
+
export function selectAccount(state, company, now = new Date()) {
|
|
238
|
+
return companyAccount(urnOf(company), state, now);
|
|
239
|
+
}
|
|
240
|
+
/** Sales for a period from the store's invoices and payments (see `salesSummary`). */
|
|
241
|
+
export function selectSales(state, range, now = new Date()) {
|
|
242
|
+
return salesSummary(state, range, now);
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAgB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAuB,MAAM,cAAc,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAoB,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAoB,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAkB,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAqB,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAoB,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,YAAY,GAUb,MAAM,YAAY,CAAC;AAmCpB,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAG3F,CAAC;AAEF,MAAM,KAAK,GAAkB;IAC3B,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,SAAS,EAAE,EAAE;IACb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ts';
|
|
2
|
+
import type { Deal, Lead, Remittance } from './types.ts';
|
|
3
|
+
export interface SalesTarget {
|
|
4
|
+
/** The target per currency: leads' target values, each qualified lead's replaced by its deal's. */
|
|
5
|
+
target: MoneyTotals;
|
|
6
|
+
/** Won deals' target values per currency. */
|
|
7
|
+
won: MoneyTotals;
|
|
8
|
+
/** Payments received less refunds on the deals' invoices, per currency. */
|
|
9
|
+
received: MoneyTotals;
|
|
10
|
+
/** Received against target per currency, 0 to 1 (more than 1 past the target). */
|
|
11
|
+
progress: Readonly<Record<string, number>>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The sales target and progress towards it. The target is the sum of the leads' target values, using the deal's target
|
|
15
|
+
* value instead once a lead is qualified into a deal. Deals created without a lead count too, as they're qualified
|
|
16
|
+
* already; unqualified leads don't. Lost deals stay in the target, so losing one doesn't make progress look better.
|
|
17
|
+
* Progress is the payments received against the target (decided 24 Oct 2026): money in on the invoices raised for the
|
|
18
|
+
* deals (`Deal.invoices`), refunds taken off. Payments on invoices without a deal, such as repeat orders, don't count.
|
|
19
|
+
*/
|
|
20
|
+
export declare function salesTarget(leads: readonly Lead[], deals: readonly Deal[], remittances: readonly Remittance[]): SalesTarget;
|
|
21
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../src/target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAIxD,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,mGAAmG;IACnG,MAAM,EAAE,WAAW,CAAC;IACpB,6CAA6C;IAC7C,GAAG,EAAE,WAAW,CAAC;IACjB,2EAA2E;IAC3E,QAAQ,EAAE,WAAW,CAAC;IACtB,kFAAkF;IAClF,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC5C;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,WAAW,EAAE,SAAS,UAAU,EAAE,GACjC,WAAW,CAsBb"}
|
package/dist/target.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { addMoney } from "./money.js";
|
|
2
|
+
import { paymentsReceived } from "./invoices.js";
|
|
3
|
+
import { leadOutcome } from "./leads.js";
|
|
4
|
+
import { dealOutcome } from "./pipeline.js";
|
|
5
|
+
/**
|
|
6
|
+
* The sales target and progress towards it. The target is the sum of the leads' target values, using the deal's target
|
|
7
|
+
* value instead once a lead is qualified into a deal. Deals created without a lead count too, as they're qualified
|
|
8
|
+
* already; unqualified leads don't. Lost deals stay in the target, so losing one doesn't make progress look better.
|
|
9
|
+
* Progress is the payments received against the target (decided 24 Oct 2026): money in on the invoices raised for the
|
|
10
|
+
* deals (`Deal.invoices`), refunds taken off. Payments on invoices without a deal, such as repeat orders, don't count.
|
|
11
|
+
*/
|
|
12
|
+
export function salesTarget(leads, deals, remittances) {
|
|
13
|
+
const fromLeads = new Set(deals.flatMap((deal) => (deal.leadSource ? [deal.leadSource.urn] : [])));
|
|
14
|
+
let target = {};
|
|
15
|
+
let won = {};
|
|
16
|
+
for (const deal of deals) {
|
|
17
|
+
target = addMoney(target, deal.targetValue);
|
|
18
|
+
if (dealOutcome(deal) === 'WON')
|
|
19
|
+
won = addMoney(won, deal.targetValue);
|
|
20
|
+
}
|
|
21
|
+
for (const lead of leads) {
|
|
22
|
+
if (leadOutcome(lead) === 'CLOSED')
|
|
23
|
+
continue;
|
|
24
|
+
// A lead that became one of these deals (its leadSource) is counted by its deal's value above.
|
|
25
|
+
if (fromLeads.has(lead.urn))
|
|
26
|
+
continue;
|
|
27
|
+
target = addMoney(target, lead.targetValue);
|
|
28
|
+
}
|
|
29
|
+
const invoiced = new Set(deals.flatMap((deal) => deal.invoices.map((invoice) => invoice.urn)));
|
|
30
|
+
const received = paymentsReceived(remittances.filter((remittance) => invoiced.has(remittance.paymentInvoice.urn)));
|
|
31
|
+
const progress = Object.fromEntries(Object.entries(target)
|
|
32
|
+
.filter(([, minor]) => minor > 0)
|
|
33
|
+
.map(([currency, minor]) => [currency, (received[currency] ?? 0) / minor]));
|
|
34
|
+
return { target, won, received, progress };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.js","sourceRoot":"","sources":["../src/target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAc5C;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,KAAsB,EACtB,KAAsB,EACtB,WAAkC;IAElC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACnG,IAAI,MAAM,GAAgB,EAAE,CAAC;IAC7B,IAAI,GAAG,GAAgB,EAAE,CAAC;IAC1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC5C,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,KAAK;YAAE,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,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@baack-software/baack-ts-client';
|
|
2
|
+
import type { Ref } from '@baack-software/baack-ts-tasks';
|
|
3
|
+
/**
|
|
4
|
+
* An amount of money in whole minor units (pence, cents), as content money items write it: `unitValue: 125000` with
|
|
5
|
+
* `currencyCode: "GBP"` is 1,250.00 GBP. `formattedValue` is the server's text for it, when it sends one. Decided
|
|
6
|
+
* 24 Oct 2026; invoices move to the same format.
|
|
7
|
+
*/
|
|
8
|
+
export interface Money {
|
|
9
|
+
unitValue: number;
|
|
10
|
+
/** An ISO 4217 code such as `GBP`. */
|
|
11
|
+
currencyCode: string;
|
|
12
|
+
formattedValue?: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** Where a lead came from. */
|
|
15
|
+
export type LeadSource = 'WEBSITE' | 'REFERRAL' | 'SOCIAL' | 'EMAIL' | 'CALL' | 'ADS' | 'EVENT' | 'UNKNOWN';
|
|
16
|
+
/** How far a lead has got: only progress. How it ended is its `outcome`. */
|
|
17
|
+
export type LeadStatus = 'NEW' | 'CONTACTED' | 'QUALIFIED';
|
|
18
|
+
/**
|
|
19
|
+
* How a lead ended, as a deal's outcome does: still being worked, converted into a deal (a lead's won), or closed as
|
|
20
|
+
* unqualified (a lead's lost).
|
|
21
|
+
*/
|
|
22
|
+
export type LeadOutcome = 'IN_PROGRESS' | 'CONVERTED' | 'CLOSED';
|
|
23
|
+
/**
|
|
24
|
+
* A prospect who hasn't been qualified yet. People are always identities, so their names are held securely as person
|
|
25
|
+
* names: a lead links a contact identity rather than holding a name, and a business by its contact company, whose name
|
|
26
|
+
* is the company's. A lead converted into a deal is the deal's `leadSource`.
|
|
27
|
+
*/
|
|
28
|
+
export interface Lead {
|
|
29
|
+
urn: string;
|
|
30
|
+
url?: string | null;
|
|
31
|
+
/** The company whose lead this is. */
|
|
32
|
+
owner: Ref;
|
|
33
|
+
/** What the lead is about, for example "Club robes for the spring season". */
|
|
34
|
+
title: string;
|
|
35
|
+
/** The person, as an identity. */
|
|
36
|
+
contactIdentity?: Ref | null;
|
|
37
|
+
/** The prospect's company, which holds its name. A consumer's lead has none. */
|
|
38
|
+
contactCompany?: Ref | null;
|
|
39
|
+
source: LeadSource;
|
|
40
|
+
status: LeadStatus;
|
|
41
|
+
/** In progress, converted or closed. In progress when absent. */
|
|
42
|
+
outcome?: LeadOutcome | null;
|
|
43
|
+
/** What the lead could be worth. Counts towards the sales target until the lead is converted into a deal. */
|
|
44
|
+
targetValue?: Money | null;
|
|
45
|
+
/** Who's working the lead. */
|
|
46
|
+
assignee?: Ref | null;
|
|
47
|
+
/** Why the lead was closed as unqualified. */
|
|
48
|
+
closedReason?: string | null;
|
|
49
|
+
/** A content entity for the business's own fields about the lead, as companies have. */
|
|
50
|
+
entity?: Ref | null;
|
|
51
|
+
createdTimestamp: string;
|
|
52
|
+
updatedTimestamp?: string | null;
|
|
53
|
+
}
|
|
54
|
+
/** How a deal stands: still open, won or lost. */
|
|
55
|
+
export type DealOutcome = 'OPEN' | 'WON' | 'LOST';
|
|
56
|
+
/**
|
|
57
|
+
* A deal pipeline: any workflow. Workflows are dynamic and not about deals, so a deal carries its own outcome and
|
|
58
|
+
* probability; its stage is only where it is in the workflow.
|
|
59
|
+
*/
|
|
60
|
+
export type Pipeline = Workflow;
|
|
61
|
+
/** A pipeline's stage: a workflow stage. */
|
|
62
|
+
export type PipelineStage = WorkflowStage;
|
|
63
|
+
/**
|
|
64
|
+
* A qualified opportunity, moving through a pipeline (a workflow) stage by stage until it's won or lost.
|
|
65
|
+
*/
|
|
66
|
+
export interface Deal {
|
|
67
|
+
urn: string;
|
|
68
|
+
url?: string | null;
|
|
69
|
+
owner: Ref;
|
|
70
|
+
title: string;
|
|
71
|
+
/** The customer's companies: usually one. */
|
|
72
|
+
contactCompanies: Ref[];
|
|
73
|
+
/** The people involved, as identities. */
|
|
74
|
+
contactIdentities: Ref[];
|
|
75
|
+
/** The deal's stage, in its pipeline (any workflow): named as a task's stage is. */
|
|
76
|
+
workflowStage?: Ref | null;
|
|
77
|
+
/** Open, won or lost, on the deal itself rather than its stage. Open when absent. */
|
|
78
|
+
outcome?: DealOutcome | null;
|
|
79
|
+
/** The chance it's won, 0 to 100, for weighted pipeline value. */
|
|
80
|
+
probability?: number | null;
|
|
81
|
+
/** What the deal is worth. Replaces its lead's target value in the sales target. */
|
|
82
|
+
targetValue?: Money | null;
|
|
83
|
+
/** When it's expected to close. */
|
|
84
|
+
targetCloseTimestamp?: string | null;
|
|
85
|
+
/** When it was won or lost, cleared when it reopens. */
|
|
86
|
+
closeTimestamp?: string | null;
|
|
87
|
+
/** Why it was lost, as leads have `closedReason`. */
|
|
88
|
+
lostReason?: string | null;
|
|
89
|
+
assignee?: Ref | null;
|
|
90
|
+
/** The lead it was converted from. */
|
|
91
|
+
leadSource?: Ref | null;
|
|
92
|
+
/** Invoices raised for it; there may be several. The link lives here, not on the invoice. */
|
|
93
|
+
invoices: Ref[];
|
|
94
|
+
/** A content entity for the business's own fields about the deal, as companies have. */
|
|
95
|
+
entity?: Ref | null;
|
|
96
|
+
createdTimestamp: string;
|
|
97
|
+
updatedTimestamp?: string | null;
|
|
98
|
+
}
|
|
99
|
+
/** The payment invoice statuses the API has. */
|
|
100
|
+
export type InvoiceStatus = 'DRAFT' | 'IN_REVIEW' | 'AUTHORISED' | 'PENDING' | 'VOIDED' | 'PAID' | 'REFUNDED';
|
|
101
|
+
/** Whether an invoice's line prices include tax. */
|
|
102
|
+
export type LineItemTax = 'EXCLUSIVE' | 'INCLUSIVE' | 'NO_TAX';
|
|
103
|
+
/** Who pays or receives an invoice: a company, an identity, or both (a person at a company). */
|
|
104
|
+
export interface InvoiceParty {
|
|
105
|
+
company?: Ref | null;
|
|
106
|
+
identity?: Ref | null;
|
|
107
|
+
}
|
|
108
|
+
/** An invoice line, as the API has it (`/n/v1/invoiceline/`). */
|
|
109
|
+
export interface InvoiceLine {
|
|
110
|
+
urn: string;
|
|
111
|
+
lineNumber?: number | null;
|
|
112
|
+
description?: string | null;
|
|
113
|
+
itemCode?: string | null;
|
|
114
|
+
quantity?: number | null;
|
|
115
|
+
/** In major units (pounds), unlike the line's money amounts. */
|
|
116
|
+
unitPrice?: number | null;
|
|
117
|
+
price?: Money | null;
|
|
118
|
+
tax?: Money | null;
|
|
119
|
+
discountPrice?: Money | null;
|
|
120
|
+
discountRate?: number | null;
|
|
121
|
+
taxName?: string | null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A payment invoice (`/n/v1/paymentinvoice/`): its amounts as money in `currencyCode`, its lines, and the payments and
|
|
125
|
+
* refunds against it (`remittances`). Deals link to their invoices (`Deal.invoices`).
|
|
126
|
+
*/
|
|
127
|
+
export interface Invoice {
|
|
128
|
+
urn: string;
|
|
129
|
+
url?: string | null;
|
|
130
|
+
owner: Ref;
|
|
131
|
+
/** Who pays. */
|
|
132
|
+
remitter?: InvoiceParty | null;
|
|
133
|
+
/** Who the invoice is addressed to. */
|
|
134
|
+
recipient?: InvoiceParty | null;
|
|
135
|
+
status: InvoiceStatus;
|
|
136
|
+
currencyCode: string;
|
|
137
|
+
lineItemTax?: LineItemTax | null;
|
|
138
|
+
subTotal?: Money | null;
|
|
139
|
+
discount?: Money | null;
|
|
140
|
+
tax?: Money | null;
|
|
141
|
+
/** Required on create. */
|
|
142
|
+
total: Money;
|
|
143
|
+
paid?: Money | null;
|
|
144
|
+
refunded?: Money | null;
|
|
145
|
+
issuedTimestamp?: string | null;
|
|
146
|
+
dueTimestamp?: string | null;
|
|
147
|
+
fullyPaidTimestamp?: string | null;
|
|
148
|
+
lines?: InvoiceLine[];
|
|
149
|
+
/** Payments and refunds against it, as the API lists them on the invoice. */
|
|
150
|
+
remittances?: Remittance[];
|
|
151
|
+
updatedTimestamp?: string | null;
|
|
152
|
+
}
|
|
153
|
+
/** Whether a remittance is money received for an invoice or a refund paid back. */
|
|
154
|
+
export type RemittanceDirection = 'PAYMENT' | 'REFUND';
|
|
155
|
+
export type RemittanceStatus = 'RECEIVED' | 'FAILED' | 'REVERSED';
|
|
156
|
+
export type RemittanceMethod = 'BANK_TRANSFER' | 'CARD_PAYMENT' | 'DIRECT_DEBIT' | 'CASH' | 'E_WALLET' | 'OTHER';
|
|
157
|
+
/**
|
|
158
|
+
* One payment received against an invoice, or a refund paid back (`/n/v1/invoiceremittance/`). It has no owner of its
|
|
159
|
+
* own: a company's remittances are its invoices'. An invoice's `paid`, `refunded`, `status` and `fullyPaidTimestamp`
|
|
160
|
+
* follow from them (see `invoiceFromRemittances`).
|
|
161
|
+
*/
|
|
162
|
+
export interface Remittance {
|
|
163
|
+
urn: string;
|
|
164
|
+
url?: string | null;
|
|
165
|
+
paymentInvoice: Ref;
|
|
166
|
+
remittanceDirection: RemittanceDirection;
|
|
167
|
+
remittanceStatus: RemittanceStatus;
|
|
168
|
+
remittanceMethod: RemittanceMethod;
|
|
169
|
+
value: Money;
|
|
170
|
+
/** The bank or card reference. */
|
|
171
|
+
reference?: string | null;
|
|
172
|
+
/** Who paid: a company, an identity, or both. */
|
|
173
|
+
remittingCompany?: Ref | null;
|
|
174
|
+
remittingIdentity?: Ref | null;
|
|
175
|
+
receivedTimestamp: string;
|
|
176
|
+
}
|
|
177
|
+
/** The CRM concepts, each served by the API or by sample data (see CrmClient). */
|
|
178
|
+
export type CrmConcept = 'leads' | 'deals' | 'pipelines' | 'invoices' | 'remittances';
|
|
179
|
+
export declare const CRM_CONCEPTS: readonly CrmConcept[];
|
|
180
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAO1D;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,YAAY,EAAE,MAAM,CAAC;IACr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B,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAC9B,iBAAiB,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,kFAAkF;AAClF,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,GAAG,aAAa,CAAC;AAEtF,eAAO,MAAM,YAAY,EAAE,SAAS,UAAU,EAA+D,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAyMA,MAAM,CAAC,MAAM,YAAY,GAA0B,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,102 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baack-software/baack-ts-crm",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "TypeScript tools for a Baack CRM: leads, deals, pipelines, invoices and payments, with helpers, sample data and (later) shadcn/ui components",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Baack",
|
|
7
|
+
"CRM",
|
|
8
|
+
"leads",
|
|
9
|
+
"deals",
|
|
10
|
+
"sales"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/Baack-Software/baack-ts-crm#readme",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Baack-Software/baack-ts-crm.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"author": "baack-dakkad",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"module": "dist/index.js",
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./mock": {
|
|
29
|
+
"types": "./dist/mock/index.d.ts",
|
|
30
|
+
"import": "./dist/mock/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./store": {
|
|
33
|
+
"types": "./dist/store.d.ts",
|
|
34
|
+
"import": "./dist/store.js"
|
|
35
|
+
},
|
|
36
|
+
"./react": {
|
|
37
|
+
"types": "./dist/react/index.d.ts",
|
|
38
|
+
"import": "./dist/react/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"src"
|
|
44
|
+
],
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.build.json",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build",
|
|
54
|
+
"demo": "vite --config demo/vite.config.ts",
|
|
55
|
+
"demo:build": "vite build --config demo/vite.config.ts --outDir ../demo-dist --emptyOutDir"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"@baack-software/baack-ts-client": ">=0.0.7",
|
|
59
|
+
"@baack-software/baack-ts-tasks": ">=0.0.1",
|
|
60
|
+
"react": ">=19",
|
|
61
|
+
"react-dom": ">=19",
|
|
62
|
+
"recharts": ">=3.8"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@baack-software/baack-ts-client": "file:../baack-ts-client",
|
|
66
|
+
"@baack-software/baack-ts-tasks": "file:../baack-ts-tasks",
|
|
67
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
68
|
+
"@testing-library/react": "^16.3.3",
|
|
69
|
+
"@testing-library/user-event": "^14.6.8",
|
|
70
|
+
"@types/node": "^24.0.0",
|
|
71
|
+
"@types/react": "^19.3.0",
|
|
72
|
+
"@types/react-dom": "^19.3.0",
|
|
73
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
74
|
+
"jsdom": "^30.1.2",
|
|
75
|
+
"react": "^19.3.0",
|
|
76
|
+
"react-dom": "^19.3.0",
|
|
77
|
+
"recharts": "^3.8.0",
|
|
78
|
+
"shadcn": "^4.21.0",
|
|
79
|
+
"tailwindcss": "^4.3.3",
|
|
80
|
+
"tw-animate-css": "^1.4.0",
|
|
81
|
+
"typescript": "^5.0.0",
|
|
82
|
+
"vite": "^8.3.4",
|
|
83
|
+
"vitest": "^5.0.2"
|
|
84
|
+
},
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public"
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"class-variance-authority": "^0.7.1",
|
|
90
|
+
"cn": "^0.5.0",
|
|
91
|
+
"lucide-react": "^1.56.0",
|
|
92
|
+
"radix-ui": "^1.8.1"
|
|
93
|
+
},
|
|
94
|
+
"peerDependenciesMeta": {
|
|
95
|
+
"react": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"react-dom": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|