@hanzo/crm 0.0.0-stage → 0.1.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.
- package/LICENSE-MIT +21 -0
- package/LICENSE.md +21 -0
- package/NOTICE +52 -0
- package/README.md +72 -2
- package/dist/CrmModule.d.ts +4 -0
- package/dist/CrmModule.d.ts.map +1 -0
- package/dist/CrmModule.js +78 -0
- package/dist/CrmModule.js.map +1 -0
- package/dist/crm/Access.d.ts +10 -0
- package/dist/crm/Access.d.ts.map +1 -0
- package/dist/crm/Access.js +35 -0
- package/dist/crm/Access.js.map +1 -0
- package/dist/crm/Actions.d.ts +38 -0
- package/dist/crm/Actions.d.ts.map +1 -0
- package/dist/crm/Actions.js +224 -0
- package/dist/crm/Actions.js.map +1 -0
- package/dist/crm/Create.d.ts +13 -0
- package/dist/crm/Create.d.ts.map +1 -0
- package/dist/crm/Create.js +64 -0
- package/dist/crm/Create.js.map +1 -0
- package/dist/crm/Import.d.ts +7 -0
- package/dist/crm/Import.d.ts.map +1 -0
- package/dist/crm/Import.js +94 -0
- package/dist/crm/Import.js.map +1 -0
- package/dist/crm/Record.d.ts +6 -0
- package/dist/crm/Record.d.ts.map +1 -0
- package/dist/crm/Record.js +254 -0
- package/dist/crm/Record.js.map +1 -0
- package/dist/crm/Records.d.ts +33 -0
- package/dist/crm/Records.d.ts.map +1 -0
- package/dist/crm/Records.js +275 -0
- package/dist/crm/Records.js.map +1 -0
- package/dist/crm/Timeline.d.ts +22 -0
- package/dist/crm/Timeline.d.ts.map +1 -0
- package/dist/crm/Timeline.js +117 -0
- package/dist/crm/Timeline.js.map +1 -0
- package/dist/crm/csv.d.ts +75 -0
- package/dist/crm/csv.d.ts.map +1 -0
- package/dist/crm/csv.js +300 -0
- package/dist/crm/csv.js.map +1 -0
- package/dist/crm/importer.d.ts +39 -0
- package/dist/crm/importer.d.ts.map +1 -0
- package/dist/crm/importer.js +147 -0
- package/dist/crm/importer.js.map +1 -0
- package/dist/crm/objects.d.ts +80 -0
- package/dist/crm/objects.d.ts.map +1 -0
- package/dist/crm/objects.js +167 -0
- package/dist/crm/objects.js.map +1 -0
- package/dist/crm/schema.d.ts +58 -0
- package/dist/crm/schema.d.ts.map +1 -0
- package/dist/crm/schema.js +175 -0
- package/dist/crm/schema.js.map +1 -0
- package/dist/crm/studio/Sequences.d.ts +4 -0
- package/dist/crm/studio/Sequences.d.ts.map +1 -0
- package/dist/crm/studio/Sequences.js +114 -0
- package/dist/crm/studio/Sequences.js.map +1 -0
- package/dist/crm/studio/logic.d.ts +32 -0
- package/dist/crm/studio/logic.d.ts.map +1 -0
- package/dist/crm/studio/logic.js +59 -0
- package/dist/crm/studio/logic.js.map +1 -0
- package/dist/crm/studio/style.d.ts +8 -0
- package/dist/crm/studio/style.d.ts.map +1 -0
- package/dist/crm/studio/style.js +21 -0
- package/dist/crm/studio/style.js.map +1 -0
- package/dist/crm/suppression.d.ts +11 -0
- package/dist/crm/suppression.d.ts.map +1 -0
- package/dist/crm/suppression.js +20 -0
- package/dist/crm/suppression.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/base-data/api.d.ts +48 -0
- package/dist/lib/base-data/api.d.ts.map +1 -0
- package/dist/lib/base-data/api.js +2 -0
- package/dist/lib/base-data/api.js.map +1 -0
- package/dist/lib/base-data/client.d.ts +29 -0
- package/dist/lib/base-data/client.d.ts.map +1 -0
- package/dist/lib/base-data/client.js +76 -0
- package/dist/lib/base-data/client.js.map +1 -0
- package/dist/lib/base-data/fields.d.ts +103 -0
- package/dist/lib/base-data/fields.d.ts.map +1 -0
- package/dist/lib/base-data/fields.js +251 -0
- package/dist/lib/base-data/fields.js.map +1 -0
- package/dist/lib/base-data/html.d.ts +20 -0
- package/dist/lib/base-data/html.d.ts.map +1 -0
- package/dist/lib/base-data/html.js +49 -0
- package/dist/lib/base-data/html.js.map +1 -0
- package/dist/lib/base-data/query.d.ts +50 -0
- package/dist/lib/base-data/query.d.ts.map +1 -0
- package/dist/lib/base-data/query.js +220 -0
- package/dist/lib/base-data/query.js.map +1 -0
- package/dist/lib/crm.d.ts +374 -0
- package/dist/lib/crm.d.ts.map +1 -0
- package/dist/lib/crm.js +337 -0
- package/dist/lib/crm.js.map +1 -0
- package/dist/lib/host.d.ts +117 -0
- package/dist/lib/host.d.ts.map +1 -0
- package/dist/lib/host.js +43 -0
- package/dist/lib/host.js.map +1 -0
- package/dist/nav.d.ts +7 -0
- package/dist/nav.d.ts.map +1 -0
- package/dist/nav.js +18 -0
- package/dist/nav.js.map +1 -0
- package/package.json +58 -3
package/dist/lib/crm.js
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { paragraphs, plain } from './base-data/html.js';
|
|
2
|
+
import { ApiError, currentOrg, host, restDelete, restGet, restPost, v1Url } from './host.js';
|
|
3
|
+
const enc = encodeURIComponent;
|
|
4
|
+
/** The org's Base, as the host reaches it: at the API's own address, like every CRM call. */
|
|
5
|
+
const base = () => host().base();
|
|
6
|
+
// ── Coercion helpers ────────────────────────────────────────────────────────
|
|
7
|
+
const str = (v) => (typeof v === 'string' ? v : v == null ? '' : String(v));
|
|
8
|
+
const num = (v) => {
|
|
9
|
+
if (typeof v === 'number' && Number.isFinite(v))
|
|
10
|
+
return v;
|
|
11
|
+
if (typeof v === 'string' && v.trim() !== '' && Number.isFinite(Number(v)))
|
|
12
|
+
return Number(v);
|
|
13
|
+
return 0;
|
|
14
|
+
};
|
|
15
|
+
const asRecord = (v) => v && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
16
|
+
/**
|
|
17
|
+
* A time as epoch seconds. Base writes a date as "2026-10-18 21:30:00.000Z" (UTC), and
|
|
18
|
+
* a calendar string without a zone is read as UTC too, never in the browser's zone.
|
|
19
|
+
*/
|
|
20
|
+
export const time = (v) => {
|
|
21
|
+
if (typeof v === 'number' && Number.isFinite(v))
|
|
22
|
+
return v;
|
|
23
|
+
const s = str(v).trim();
|
|
24
|
+
if (!s)
|
|
25
|
+
return 0;
|
|
26
|
+
const iso = /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d(\.\d+)?Z?$/.test(s) ? `${s.replace(' ', 'T').replace(/Z?$/, 'Z')}` : s;
|
|
27
|
+
const t = Date.parse(iso);
|
|
28
|
+
return Number.isFinite(t) ? Math.floor(t / 1000) : 0;
|
|
29
|
+
};
|
|
30
|
+
/** A time as Base stores a date: "2026-10-30 14:05:00.000Z". */
|
|
31
|
+
export const stamp = (d = new Date()) => d.toISOString().replace('T', ' ');
|
|
32
|
+
// An editor field's HTML and its text live with the rest of Base's field shapes.
|
|
33
|
+
export { paragraphs, plain };
|
|
34
|
+
const MAIL_STATUSES = ['sent', 'suppressed', 'failed', 'delivered', 'opened', 'clicked', 'bounced', 'complained'];
|
|
35
|
+
/** A status the cloud names, or `sent` for a mail with none. */
|
|
36
|
+
const mailStatus = (v) => MAIL_STATUSES.find((m) => m === v) ?? 'sent';
|
|
37
|
+
/** Whether a status means the mail reached the inbox. */
|
|
38
|
+
export const reached = (s) => s === 'delivered' || s === 'opened' || s === 'clicked';
|
|
39
|
+
/** The refusals as the route answers them; anything malformed is dropped. */
|
|
40
|
+
export function refusalsOf(raw) {
|
|
41
|
+
if (!Array.isArray(raw))
|
|
42
|
+
return [];
|
|
43
|
+
return raw.flatMap((x) => {
|
|
44
|
+
const r = asRecord(x);
|
|
45
|
+
const address = str(r.address);
|
|
46
|
+
return address ? [{ address, status: num(r.status) || 422, reason: str(r.reason) }] : [];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Why the verifier gave no answer, in the reason a caller shows. */
|
|
50
|
+
const unanswered = (e) => e instanceof ApiError && e.status === 401 ? 'sign_in_required' : e instanceof ApiError && e.status === 429 ? 'rate_limited' : 'verifier_unreachable';
|
|
51
|
+
/** The answer read: the first failing check decides; a check that could not run leaves the address unverified. */
|
|
52
|
+
export function judge(email, w) {
|
|
53
|
+
const c = w.checks ?? {};
|
|
54
|
+
const asked = [c.syntax, c.domain, c.mx, c.smtp].filter(Boolean);
|
|
55
|
+
const failed = asked.find((x) => x.status === 'fail');
|
|
56
|
+
const disposable = Boolean(c.classification?.disposable);
|
|
57
|
+
const open = asked.some((x) => x.status === 'unknown');
|
|
58
|
+
const status = failed ? 'invalid' : disposable ? 'disposable' : open || asked.length === 0 ? 'unverified' : 'verified';
|
|
59
|
+
return {
|
|
60
|
+
email,
|
|
61
|
+
status,
|
|
62
|
+
valid: status === 'verified',
|
|
63
|
+
reachable: status === 'verified' ? 'yes' : status === 'unverified' ? 'unknown' : 'no',
|
|
64
|
+
reason: failed?.reason || (disposable ? 'disposable_domain' : open ? 'check_inconclusive' : status === 'verified' ? 'ok' : 'nothing_checked'),
|
|
65
|
+
domain: c.syntax?.domain,
|
|
66
|
+
hasMx: c.mx?.status === 'pass',
|
|
67
|
+
disposable,
|
|
68
|
+
role: Boolean(c.classification?.role),
|
|
69
|
+
free: Boolean(c.classification?.free),
|
|
70
|
+
suggestion: w.suggestions?.[0]?.email,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The activities filter for a timeline. A candidate's is read by its own relation:
|
|
75
|
+
* asked by none of these, it read the mail filed to an empty address, which is
|
|
76
|
+
* nothing, so a logged call or meeting, and the application itself, never showed
|
|
77
|
+
* (hanzo-inc/cloud#478).
|
|
78
|
+
*/
|
|
79
|
+
export function timelineFilter(who) {
|
|
80
|
+
const q = (v) => v.replace(/["\\]/g, '');
|
|
81
|
+
if (who.person)
|
|
82
|
+
return `person = "${q(who.person)}"`;
|
|
83
|
+
if (who.company)
|
|
84
|
+
return `company = "${q(who.company)}"`;
|
|
85
|
+
if (who.opportunity)
|
|
86
|
+
return `opportunity = "${q(who.opportunity)}"`;
|
|
87
|
+
if (who.candidate)
|
|
88
|
+
return `candidate = "${q(who.candidate)}"`;
|
|
89
|
+
return `data.to = "${q((who.email || '').trim().toLowerCase())}"`;
|
|
90
|
+
}
|
|
91
|
+
/** What a form filed beside its answers, worth showing: the fields a person typed. */
|
|
92
|
+
const FORM_FIELDS = [
|
|
93
|
+
'company', 'role', 'size', 'need', 'message', 'transcript', 'plan', 'seats',
|
|
94
|
+
'rating', 'comment', 'surface', 'article', 'priority', 'program', 'source',
|
|
95
|
+
'public_id', 'website', 'country', 'amount',
|
|
96
|
+
];
|
|
97
|
+
export function normalizeTimelineEvent(raw) {
|
|
98
|
+
const r = asRecord(raw);
|
|
99
|
+
const d = asRecord(r.data);
|
|
100
|
+
const answers = Array.isArray(d.answers)
|
|
101
|
+
? d.answers.map((a) => asRecord(a)).map((a) => ({ question: str(a.question).trim(), answer: str(a.answer).trim() })).filter((a) => a.question && a.answer)
|
|
102
|
+
: [];
|
|
103
|
+
const filed = str(r.kind) === 'form' ? FORM_FIELDS.filter((k) => str(d[k]).trim()).map((k) => ({ question: k[0].toUpperCase() + k.slice(1), answer: str(d[k]).trim() })) : [];
|
|
104
|
+
return {
|
|
105
|
+
id: str(r.id),
|
|
106
|
+
kind: str(r.kind),
|
|
107
|
+
direction: str(r.direction),
|
|
108
|
+
subject: str(r.subject),
|
|
109
|
+
snippet: str(r.snippet),
|
|
110
|
+
body: plain(str(r.body)),
|
|
111
|
+
at: time(r.at) || time(r.created) || time(r.createdAt),
|
|
112
|
+
to: str(d.to),
|
|
113
|
+
by: str(d.by) || str(asRecord(r.created_by).name),
|
|
114
|
+
status: mailStatus(d.status),
|
|
115
|
+
rail: str(d.rail),
|
|
116
|
+
reason: str(d.reason),
|
|
117
|
+
events: Array.isArray(d.events)
|
|
118
|
+
? d.events.map((x) => asRecord(x)).map((x) => ({ status: mailStatus(x.status), at: time(x.at) })).filter((x) => x.at > 0)
|
|
119
|
+
: [],
|
|
120
|
+
answers: [...filed, ...answers],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** The cloud's `{data}` page, or nothing. */
|
|
124
|
+
const dataOf = (r) => {
|
|
125
|
+
const d = asRecord(r).data;
|
|
126
|
+
return Array.isArray(d) ? d : [];
|
|
127
|
+
};
|
|
128
|
+
const SUPPRESSION_SCOPES = ['address', 'domain', 'platform'];
|
|
129
|
+
// ── The API ─────────────────────────────────────────────────────────────────
|
|
130
|
+
/** A collection's schema, read once per page load: fields do not change under a person working. */
|
|
131
|
+
const schemas = new Map();
|
|
132
|
+
export const CrmApi = {
|
|
133
|
+
/** Whether a resume is a file uploaded to the org's storage (`/v1/s3/buckets/…`). */
|
|
134
|
+
isUpload: (u) => u.startsWith(`${v1Url('s3/buckets/')}`),
|
|
135
|
+
/** The signed download of an uploaded file: the org's own, for a member alone. */
|
|
136
|
+
download: (u) => restGet(u).then((r) => str(r?.url)),
|
|
137
|
+
/**
|
|
138
|
+
* Whether `org` has the CRM: its `crm` enablement, the beta. Any member reads its
|
|
139
|
+
* own org's.
|
|
140
|
+
*/
|
|
141
|
+
beta: (org) => restGet(v1Url(`entitlement/orgs/${enc(org)}`)).then((r) => Array.isArray(r?.enabled) && r.enabled.includes('crm')),
|
|
142
|
+
/**
|
|
143
|
+
* A collection's fields, labels and options. Held for the page, and kept in the
|
|
144
|
+
* browser between visits so a table's first page is asked for at once: the kept
|
|
145
|
+
* schema answers now and the server's replaces it for the next read. `fresh` asks
|
|
146
|
+
* the server and waits.
|
|
147
|
+
*/
|
|
148
|
+
schema: (collection, fresh = false) => {
|
|
149
|
+
const held = schemas.get(collection);
|
|
150
|
+
if (held && !fresh)
|
|
151
|
+
return held;
|
|
152
|
+
const key = `hanzo.crm.schema.${currentOrg()}.${collection}`;
|
|
153
|
+
const read = base()
|
|
154
|
+
.getCollection(collection)
|
|
155
|
+
.then((c) => {
|
|
156
|
+
if (!c)
|
|
157
|
+
throw new ApiError(`The CRM has no ${collection}.`, 404);
|
|
158
|
+
try {
|
|
159
|
+
localStorage.setItem(key, JSON.stringify(c));
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
/* storage full or off: the next visit asks again */
|
|
163
|
+
}
|
|
164
|
+
return c;
|
|
165
|
+
});
|
|
166
|
+
let kept = null;
|
|
167
|
+
if (!fresh) {
|
|
168
|
+
try {
|
|
169
|
+
const raw = typeof localStorage !== 'undefined' ? localStorage.getItem(key) : null;
|
|
170
|
+
kept = raw ? JSON.parse(raw) : null;
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
kept = null;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const p = kept ? Promise.resolve(kept) : read;
|
|
177
|
+
read.then((c) => schemas.set(collection, Promise.resolve(c))).catch(() => schemas.delete(collection));
|
|
178
|
+
schemas.set(collection, p);
|
|
179
|
+
return p;
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* Grow the org's CRM to the module this cloud ships (POST /v1/base/modules/crm):
|
|
183
|
+
* what is missing is added, and nothing the org has is changed. Org admins only;
|
|
184
|
+
* the schemas read before it are read again after.
|
|
185
|
+
*/
|
|
186
|
+
grow: async () => {
|
|
187
|
+
const g = asRecord(await restPost(v1Url('base/modules/crm'), {}));
|
|
188
|
+
schemas.clear();
|
|
189
|
+
const grown = asRecord(g.grown);
|
|
190
|
+
const created = Array.isArray(g.created) ? g.created : [];
|
|
191
|
+
return { grew: created.length > 0 || Object.values(grown).some((v) => Array.isArray(v) && v.length > 0) };
|
|
192
|
+
},
|
|
193
|
+
/** One page of records, searched, filtered and sorted by Base. */
|
|
194
|
+
list: (collection, q) => base().listRecords(collection, q),
|
|
195
|
+
/** Every record a query admits, page by page, up to `max`, for an export or a bulk action. */
|
|
196
|
+
each: async (collection, q, max, onPage) => {
|
|
197
|
+
const out = [];
|
|
198
|
+
for (let page = 1; out.length < max; page++) {
|
|
199
|
+
const r = await base().listRecords(collection, { ...q, page, perPage: 500 });
|
|
200
|
+
out.push(...r.items);
|
|
201
|
+
onPage?.(out.length, Math.min(max, r.totalItems));
|
|
202
|
+
if (page >= r.totalPages || r.items.length < 500)
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
return out.slice(0, max);
|
|
206
|
+
},
|
|
207
|
+
get: (collection, id, expand) => expand ? base().listRecords(collection, { filter: `id = "${id.replace(/"/g, '')}"`, perPage: 1, expand, skipTotal: true }).then((r) => {
|
|
208
|
+
if (!r.items[0])
|
|
209
|
+
throw new ApiError('That record is not here.', 404);
|
|
210
|
+
return r.items[0];
|
|
211
|
+
}) : base().getRecord(collection, id),
|
|
212
|
+
create: (collection, body) => base().createRecord(collection, body),
|
|
213
|
+
update: (collection, id, body) => base().updateRecord(collection, id, body),
|
|
214
|
+
remove: (collection, id) => base().deleteRecord(collection, id),
|
|
215
|
+
/**
|
|
216
|
+
* A record's timeline: every activity filed on it, newest first. A person with no
|
|
217
|
+
* record yet is read by the mail filed to their address.
|
|
218
|
+
*/
|
|
219
|
+
timeline: (who) => {
|
|
220
|
+
return base()
|
|
221
|
+
.listRecords('activities', { filter: timelineFilter(who), sort: '-at', perPage: 200, skipTotal: true })
|
|
222
|
+
.then((r) => r.items.map(normalizeTimelineEvent).filter((e) => e.id));
|
|
223
|
+
},
|
|
224
|
+
email: {
|
|
225
|
+
/** One address through POST /v1/email/verify, signed in. `smtp` also asks the mail host. */
|
|
226
|
+
verify: async (email, opts) => {
|
|
227
|
+
const clean = email.trim().toLowerCase();
|
|
228
|
+
const checks = ['syntax', 'domain', 'mx', 'classification', ...(opts?.smtp ? ['smtp'] : [])];
|
|
229
|
+
try {
|
|
230
|
+
return judge(clean, await restPost(v1Url('email/verify'), { email: clean, checks, suggestions: true }));
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
return { email: clean, status: 'unverified', valid: false, reachable: 'unknown', reason: unanswered(e), hasMx: false, disposable: false, role: false, free: false };
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
/**
|
|
237
|
+
* An address's domain and whether it is free mail, by the verifier's own list
|
|
238
|
+
* (POST /v1/email/verify, syntax + classification: no DNS, no mailbox probe).
|
|
239
|
+
* Null when it cannot say.
|
|
240
|
+
*/
|
|
241
|
+
classify: async (email) => {
|
|
242
|
+
try {
|
|
243
|
+
const w = await restPost(v1Url('email/verify'), { email: email.trim().toLowerCase(), checks: ['syntax', 'classification'] });
|
|
244
|
+
const domain = w.checks?.syntax?.status === 'pass' ? str(w.checks.syntax.domain) : '';
|
|
245
|
+
const c = w.checks?.classification;
|
|
246
|
+
return domain && c?.status === 'pass' ? { domain, free: Boolean(c.free) } : null;
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
/**
|
|
253
|
+
* One message through POST /v1/email. The cloud files it on the recipient's CRM
|
|
254
|
+
* record and refuses a suppressed address or company; a refusal or a failure is
|
|
255
|
+
* thrown, never recorded here as sent.
|
|
256
|
+
*/
|
|
257
|
+
sendMessage: async (input) => {
|
|
258
|
+
try {
|
|
259
|
+
const r = asRecord(await restPost(v1Url('email'), input));
|
|
260
|
+
return { messages: Array.isArray(r.messages) ? r.messages : [], refused: refusalsOf(r.refused) };
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
// Every recipient refused is a 422 carrying the same answer: said per address, not thrown.
|
|
264
|
+
const refused = e instanceof ApiError && e.status === 422 ? refusalsOf(asRecord(e.body).refused) : [];
|
|
265
|
+
if (refused.length)
|
|
266
|
+
return { messages: [], refused };
|
|
267
|
+
throw e;
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
/**
|
|
271
|
+
* One email to one person from their record (POST /v1/marketing/mail): the org's
|
|
272
|
+
* own mailbox when it has one, else notify, never to an address that opted out,
|
|
273
|
+
* filed on the person's timeline. Org admins and SuperAdmins send.
|
|
274
|
+
*/
|
|
275
|
+
sendCrmMail: async (input) => {
|
|
276
|
+
const res = await restPost(v1Url('marketing/mail'), input);
|
|
277
|
+
return { sent: Boolean(res?.sent), at: res?.at || new Date().toISOString() };
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
marketing: {
|
|
281
|
+
/** The org's sequences, most recently updated first. */
|
|
282
|
+
listSequences: async () => dataOf(await restGet(v1Url('marketing/sequences?limit=200'))),
|
|
283
|
+
/** One sequence and its steps in send order. */
|
|
284
|
+
getSequence: async (id) => {
|
|
285
|
+
const r = asRecord(await restGet(v1Url(`marketing/sequences/${enc(id)}`)));
|
|
286
|
+
return { sequence: r.sequence, steps: Array.isArray(r.steps) ? r.steps : [] };
|
|
287
|
+
},
|
|
288
|
+
/** A new sequence, as a draft: nothing sends until it is made active and someone is enrolled. */
|
|
289
|
+
createSequence: (name) => restPost(v1Url('marketing/sequences'), { name, status: 'draft' }),
|
|
290
|
+
/** Append a message: `delaySeconds` after the previous step, or after enrollment for the first. */
|
|
291
|
+
addStep: (id, step) => restPost(v1Url(`marketing/sequences/${enc(id)}/steps`), step),
|
|
292
|
+
/** draft, active or archived; only an active sequence takes enrollments. */
|
|
293
|
+
setSequenceStatus: (id, status) => restPost(v1Url(`marketing/sequences/${enc(id)}/status`), { status }),
|
|
294
|
+
/** Enroll one address or a saved audience; the sequence must be active. */
|
|
295
|
+
enroll: (id, who) => restPost(v1Url(`marketing/sequences/${enc(id)}/enroll`), { ...who, channel: 'email' }),
|
|
296
|
+
/** Everyone walking a sequence, in any state, most recently enrolled first. */
|
|
297
|
+
listEnrollments: async (id) => dataOf(await restGet(v1Url(`marketing/sequences/${enc(id)}/enrollments?limit=1000`))),
|
|
298
|
+
/** Stop one person's walk; a completed or canceled one reads as not found. */
|
|
299
|
+
cancelEnrollment: (id, eid) => restPost(v1Url(`marketing/sequences/${enc(id)}/enrollments/${enc(eid)}/cancel`), {}),
|
|
300
|
+
/** The org's saved audiences. */
|
|
301
|
+
listAudiences: async () => dataOf(await restGet(v1Url('marketing/audiences?limit=200'))),
|
|
302
|
+
/** Every address the org's send gate refuses, newest first (GET /v1/marketing/suppressions). */
|
|
303
|
+
listSuppressions: async () => {
|
|
304
|
+
const res = await restGet(v1Url('marketing/suppressions?limit=500'));
|
|
305
|
+
return res?.data ?? [];
|
|
306
|
+
},
|
|
307
|
+
/** Opt one address out of email for the org. The cloud refuses a member who is not an org admin; that is thrown. */
|
|
308
|
+
addSuppression: (address, reason) => restPost(v1Url('marketing/suppressions'), { channel: 'email', address: address.trim().toLowerCase(), reason }),
|
|
309
|
+
/** One address against the send gate; any failure to answer is `unknown`, with why. */
|
|
310
|
+
checkSuppression: async (address) => {
|
|
311
|
+
let r;
|
|
312
|
+
try {
|
|
313
|
+
r = await restGet(v1Url(`marketing/suppressions/check?address=${enc(address.trim().toLowerCase())}`));
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
if (e instanceof ApiError && e.status === 404)
|
|
317
|
+
return { state: 'unknown', why: 'The suppression check is not available yet.' };
|
|
318
|
+
return { state: 'unknown', why: e instanceof Error ? e.message : 'The suppression check failed.' };
|
|
319
|
+
}
|
|
320
|
+
if (typeof r?.suppressed !== 'boolean')
|
|
321
|
+
return { state: 'unknown', why: 'The suppression check gave no answer.' };
|
|
322
|
+
if (!r.suppressed)
|
|
323
|
+
return { state: 'clear' };
|
|
324
|
+
const scope = SUPPRESSION_SCOPES.find((x) => x === r.scope);
|
|
325
|
+
return { state: 'suppressed', reason: typeof r.reason === 'string' && r.reason ? r.reason : undefined, scope };
|
|
326
|
+
},
|
|
327
|
+
/**
|
|
328
|
+
* Re-subscribe one entry on email: an address, or a company as "@example.com"
|
|
329
|
+
* (DELETE /v1/marketing/suppressions?address=&channel=, 204; 404 when it was not
|
|
330
|
+
* on the list). Org admin or SuperAdmin; the cloud refuses anyone else.
|
|
331
|
+
*/
|
|
332
|
+
removeSuppression: (entry) => restDelete(v1Url(`marketing/suppressions?address=${enc(entry.trim().toLowerCase())}&channel=email`)),
|
|
333
|
+
/** Opt a whole company out of email: the "@domain" entry every address at it answers to. */
|
|
334
|
+
suppressCompany: (domain, reason) => CrmApi.marketing.addSuppression(`@${domain.trim().toLowerCase().replace(/^@/, '')}`, reason),
|
|
335
|
+
},
|
|
336
|
+
};
|
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once, before it draws it.
|
|
3
|
+
*
|
|
4
|
+
* The CRM is one product drawn by more than one app: Hanzo Cloud's console (at
|
|
5
|
+
* /crm, and as Hanzo CRM on crm.<brand>) and Hanzo Team (at /crm). What it keeps
|
|
6
|
+
* is the org's own Base (hanzoai/base module `crm`) and the cloud's mail and
|
|
7
|
+
* drip, so every app reads the same records. What it cannot know is how this app
|
|
8
|
+
* signs a request, which org it works in, who is signed in, how it changes the
|
|
9
|
+
* address and what brand it wears. The host says, through `configureCrm`:
|
|
10
|
+
*
|
|
11
|
+
* configureCrm({
|
|
12
|
+
* v1Url, get, post, del, // plain-JSON REST over the account's credential
|
|
13
|
+
* base, // the org's Base, as a records client
|
|
14
|
+
* org, leaveOrg, // the org in scope, and the way out of it
|
|
15
|
+
* brand, // the brand's name and site
|
|
16
|
+
* gated, // whether this is the crm face, opened behind its beta
|
|
17
|
+
* useSession, useRouter, useSearchParams, // React hooks over the app's own
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* The CRM's modules were written against names the console gave these (`currentOrg`,
|
|
21
|
+
* `useRouter`, `restGet`, …); the same names are exported here, bound to the host,
|
|
22
|
+
* so what was moved out of the console reads exactly as it did there.
|
|
23
|
+
*/
|
|
24
|
+
import type { BaseClient } from './base-data/api.js';
|
|
25
|
+
/** The signed-in account, as much of it as the CRM reads. */
|
|
26
|
+
export interface CrmAccount {
|
|
27
|
+
name?: string;
|
|
28
|
+
email?: string;
|
|
29
|
+
/** A SuperAdmin acts in every org. */
|
|
30
|
+
superAdmin?: boolean;
|
|
31
|
+
/** The orgs this account administers. */
|
|
32
|
+
adminOrgs?: string[];
|
|
33
|
+
}
|
|
34
|
+
/** The session the CRM reads: who is signed in, and the way to sign out. */
|
|
35
|
+
export interface CrmSession {
|
|
36
|
+
account: CrmAccount | null;
|
|
37
|
+
signOut: () => void | Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* How the CRM changes the address. It writes the console's own addresses
|
|
41
|
+
* (`/crm`, `/crm/companies`, `/crm/deals/:id`, `?view=`); a host whose CRM lives
|
|
42
|
+
* elsewhere (crm.<brand> at its root) maps them.
|
|
43
|
+
*/
|
|
44
|
+
export interface CrmRouter {
|
|
45
|
+
push: (href: string) => void;
|
|
46
|
+
replace: (href: string) => void;
|
|
47
|
+
}
|
|
48
|
+
/** The query of the address the CRM is on. */
|
|
49
|
+
export interface CrmSearchParams {
|
|
50
|
+
get: (name: string) => string | null;
|
|
51
|
+
}
|
|
52
|
+
/** The brand the CRM wears. */
|
|
53
|
+
export interface CrmBrand {
|
|
54
|
+
/** "Hanzo Cloud", "Hanzo"; a trailing " Cloud" is dropped where the CRM names itself. */
|
|
55
|
+
brandName: string;
|
|
56
|
+
/** The brand's site, where its beta is applied for (`<websiteUrl>/beta`). */
|
|
57
|
+
websiteUrl: string;
|
|
58
|
+
}
|
|
59
|
+
export interface CrmHost {
|
|
60
|
+
/** The absolute address of an API path: `v1Url('marketing/sequences')`. */
|
|
61
|
+
v1Url: (path: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Plain-JSON REST on a full URL, signed as the account in the org. A refusal
|
|
64
|
+
* rejects with an Error carrying the HTTP `status` (and the parsed `body`).
|
|
65
|
+
*/
|
|
66
|
+
get: <T>(url: string) => Promise<T>;
|
|
67
|
+
post: <T>(url: string, body?: unknown) => Promise<T>;
|
|
68
|
+
del: <T>(url: string) => Promise<T>;
|
|
69
|
+
/** The org's Base (`/v1/base`), signed the same way. */
|
|
70
|
+
base: () => BaseClient;
|
|
71
|
+
/** The org the CRM works in. */
|
|
72
|
+
org: () => string;
|
|
73
|
+
/** Leave the org for the account's own: the way out of an org whose CRM this account's role does not reach. */
|
|
74
|
+
leaveOrg: () => void;
|
|
75
|
+
brand: () => CrmBrand;
|
|
76
|
+
/**
|
|
77
|
+
* Whether the CRM is a product opened behind its beta here (the crm face): the
|
|
78
|
+
* org's `crm` enablement is read before any CRM call, and an org without it is
|
|
79
|
+
* shown how to join. False where the CRM is one module among others.
|
|
80
|
+
*/
|
|
81
|
+
gated: boolean;
|
|
82
|
+
/** React hooks, called on every render of the CRM's screens. */
|
|
83
|
+
useSession: () => CrmSession;
|
|
84
|
+
useRouter: () => CrmRouter;
|
|
85
|
+
useSearchParams: () => CrmSearchParams | null;
|
|
86
|
+
}
|
|
87
|
+
/** Say what the CRM needs of this app. Call once, before the CRM is drawn. */
|
|
88
|
+
export declare function configureCrm(host: CrmHost): void;
|
|
89
|
+
/** The host this app configured. */
|
|
90
|
+
export declare function host(): CrmHost;
|
|
91
|
+
/**
|
|
92
|
+
* A refusal from the API: an Error carrying its HTTP `status`, and the parsed body
|
|
93
|
+
* when the caller reads more than the reason (a 422's per-recipient detail).
|
|
94
|
+
*
|
|
95
|
+
* The host's transport throws its OWN error type. What makes one an API error is
|
|
96
|
+
* its shape, not its class, so `instanceof ApiError` holds for any Error with a
|
|
97
|
+
* numeric `status`: the host's and this one alike.
|
|
98
|
+
*/
|
|
99
|
+
export declare class ApiError extends Error {
|
|
100
|
+
readonly status: number;
|
|
101
|
+
readonly body?: unknown;
|
|
102
|
+
constructor(message: string, status?: number, body?: unknown);
|
|
103
|
+
static [Symbol.hasInstance](x: unknown): boolean;
|
|
104
|
+
}
|
|
105
|
+
/** The account type the CRM's modules name. */
|
|
106
|
+
export type Account = CrmAccount;
|
|
107
|
+
export declare const v1Url: (path: string) => string;
|
|
108
|
+
export declare const restGet: <T>(url: string) => Promise<T>;
|
|
109
|
+
export declare const restPost: <T>(url: string, body?: unknown) => Promise<T>;
|
|
110
|
+
export declare const restDelete: <T = void>(url: string) => Promise<T>;
|
|
111
|
+
export declare const currentOrg: () => string;
|
|
112
|
+
export declare const leaveOrg: () => void;
|
|
113
|
+
export declare const getBrand: () => CrmBrand;
|
|
114
|
+
export declare const useSession: () => CrmSession;
|
|
115
|
+
export declare const useRouter: () => CrmRouter;
|
|
116
|
+
export declare const useSearchParams: () => CrmSearchParams | null;
|
|
117
|
+
//# sourceMappingURL=host.d.ts.map
|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I,CAAC,OAAO,MAAM,SAAS,OAAO,KAAG,OAAO,CAAC,CAAC,CAA8B,CAAA;AACjG,eAAO,MAAM,UAAU,GAAI,CAAC,GAAG,IAAI,OAAO,MAAM,KAAG,OAAO,CAAC,CAAC,CAAuB,CAAA;AACnF,eAAO,MAAM,UAAU,QAAO,MAAsB,CAAA;AACpD,eAAO,MAAM,QAAQ,QAAO,IAAyB,CAAA;AACrD,eAAO,MAAM,QAAQ,QAAO,QAA0B,CAAA;AACtD,eAAO,MAAM,UAAU,QAAO,UAAiC,CAAA;AAC/D,eAAO,MAAM,SAAS,QAAO,SAA+B,CAAA;AAC5D,eAAO,MAAM,eAAe,QAAO,eAAe,GAAG,IAAgC,CAAA"}
|
package/dist/lib/host.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
let current = null;
|
|
2
|
+
/** Say what the CRM needs of this app. Call once, before the CRM is drawn. */
|
|
3
|
+
export function configureCrm(host) {
|
|
4
|
+
current = host;
|
|
5
|
+
}
|
|
6
|
+
/** The host this app configured. */
|
|
7
|
+
export function host() {
|
|
8
|
+
if (!current)
|
|
9
|
+
throw new Error('@hanzo/crm: call configureCrm(host) before drawing the CRM.');
|
|
10
|
+
return current;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A refusal from the API: an Error carrying its HTTP `status`, and the parsed body
|
|
14
|
+
* when the caller reads more than the reason (a 422's per-recipient detail).
|
|
15
|
+
*
|
|
16
|
+
* The host's transport throws its OWN error type. What makes one an API error is
|
|
17
|
+
* its shape, not its class, so `instanceof ApiError` holds for any Error with a
|
|
18
|
+
* numeric `status`: the host's and this one alike.
|
|
19
|
+
*/
|
|
20
|
+
export class ApiError extends Error {
|
|
21
|
+
status;
|
|
22
|
+
body;
|
|
23
|
+
constructor(message, status = 0, body) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'ApiError';
|
|
26
|
+
this.status = status;
|
|
27
|
+
this.body = body;
|
|
28
|
+
}
|
|
29
|
+
static [Symbol.hasInstance](x) {
|
|
30
|
+
return x instanceof Error && typeof x.status === 'number';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const v1Url = (path) => host().v1Url(path);
|
|
34
|
+
export const restGet = (url) => host().get(url);
|
|
35
|
+
export const restPost = (url, body) => host().post(url, body);
|
|
36
|
+
export const restDelete = (url) => host().del(url);
|
|
37
|
+
export const currentOrg = () => host().org();
|
|
38
|
+
export const leaveOrg = () => host().leaveOrg();
|
|
39
|
+
export const getBrand = () => host().brand();
|
|
40
|
+
export const useSession = () => host().useSession();
|
|
41
|
+
export const useRouter = () => host().useRouter();
|
|
42
|
+
export const useSearchParams = () => host().useSearchParams();
|
|
43
|
+
//# sourceMappingURL=host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/lib/host.ts"],"names":[],"mappings":"AA6FA,IAAI,OAAO,GAAmB,IAAI,CAAA;AAElC,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAC,IAAa;IACxC,OAAO,GAAG,IAAI,CAAA;AAChB,CAAC;AAED,oCAAoC;AACpC,MAAM,UAAU,IAAI;IAClB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAA;IAC5F,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,MAAM,CAAQ;IACd,IAAI,CAAU;IACvB,YAAY,OAAe,EAAE,MAAM,GAAG,CAAC,EAAE,IAAc;QACrD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IACD,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAU;QACpC,OAAO,CAAC,YAA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AQA,MAAM,WAAW,OAAO;IACtB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,SAAS,EAAE,SAAS,OAAO,EASvC,CAAA"}
|
package/dist/nav.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CRM's pages, in the order an app's navigation lists them: People is the
|
|
3
|
+
* index (`/crm`), then each object, and Sequences, the cloud's drip, before
|
|
4
|
+
* Candidates. Each is named as its own screen names it (`deals` is the Pipeline).
|
|
5
|
+
* A host draws these with its own icons, at `/crm` and `/crm/<slug>`.
|
|
6
|
+
*/
|
|
7
|
+
import { OBJECTS } from './crm/objects.js';
|
|
8
|
+
export const CRM_PAGES = [
|
|
9
|
+
{ slug: '', label: OBJECTS.people.plural },
|
|
10
|
+
{ slug: 'companies', label: OBJECTS.companies.plural },
|
|
11
|
+
{ slug: 'deals', label: OBJECTS.deals.plural },
|
|
12
|
+
{ slug: 'fundraising', label: OBJECTS.fundraising.plural },
|
|
13
|
+
{ slug: 'tasks', label: OBJECTS.tasks.plural },
|
|
14
|
+
{ slug: 'lists', label: OBJECTS.lists.plural },
|
|
15
|
+
{ slug: 'sequences', label: 'Sequences' },
|
|
16
|
+
{ slug: 'candidates', label: OBJECTS.candidates.plural },
|
|
17
|
+
];
|
|
18
|
+
//# sourceMappingURL=nav.js.map
|
package/dist/nav.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nav.js","sourceRoot":"","sources":["../src/nav.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAQvC,MAAM,CAAC,MAAM,SAAS,GAAuB;IAC3C,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;IAC1C,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE;IACtD,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE;IAC9C,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE;IAC1D,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE;IAC9C,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE;IAC9C,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE;IACzC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE;CACzD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/crm",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Hanzo CRM — the org's people, companies, pipeline, fundraising, tasks, lists, candidates and sequences, kept in the org's own Base. One CRM for every app that has one (Hanzo Cloud's console and crm.<brand>, Hanzo Team): each app supplies its request signing, org, session, router and brand through configureCrm and draws <CrmModule />.",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./base": {
|
|
13
|
+
"types": "./dist/lib/base-data/client.d.ts",
|
|
14
|
+
"import": "./dist/lib/base-data/client.js",
|
|
15
|
+
"default": "./dist/lib/base-data/client.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"NOTICE",
|
|
25
|
+
"LICENSE-MIT"
|
|
26
|
+
],
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@hanzo/data": ">=1.4.5",
|
|
29
|
+
"@hanzo/gui": ">=8.3.5",
|
|
30
|
+
"@hanzo/ui": ">=8.29.0",
|
|
31
|
+
"@hanzogui/lucide-icons-2": "^8.3.5",
|
|
32
|
+
"react": ">=19.2.8"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@hanzo/data": "^1.4.6",
|
|
36
|
+
"@hanzo/gui": "8.3.5",
|
|
37
|
+
"@hanzo/ui": "^8.33.4",
|
|
38
|
+
"@hanzogui/lucide-icons-2": "8.3.5",
|
|
39
|
+
"@types/react": "19.2.18",
|
|
40
|
+
"react": "19.2.8",
|
|
41
|
+
"typescript": "7.0.2",
|
|
42
|
+
"vitest": "^4.1.11"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"author": "Hanzo AI <dev@hanzo.ai>",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/hanzoai/ui.git",
|
|
52
|
+
"directory": "pkg/crm"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && node ../ui/scripts/postbuild.mjs .",
|
|
56
|
+
"clean": "rm -rf dist",
|
|
57
|
+
"tc": "tsc --noEmit",
|
|
58
|
+
"typecheck": "tsc --noEmit",
|
|
59
|
+
"test": "vitest run"
|
|
60
|
+
}
|
|
6
61
|
}
|