@odla-ai/crm 0.8.0 → 0.9.1
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/dist/chunk-7LH3WGSU.js +1279 -0
- package/dist/chunk-7LH3WGSU.js.map +1 -0
- package/dist/client-CMYE9fpt.d.ts +566 -0
- package/dist/gallery/index.d.ts +17 -0
- package/dist/gallery/index.js +1080 -0
- package/dist/gallery/index.js.map +1 -0
- package/dist/index.cjs +28 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/dist/ui/index.d.ts +1 -565
- package/dist/ui/index.js +20 -1255
- package/dist/ui/index.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,1080 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActivityFeed,
|
|
3
|
+
BillingCard,
|
|
4
|
+
BulkBar,
|
|
5
|
+
CRM_NS,
|
|
6
|
+
CRM_SCHEMA,
|
|
7
|
+
CRM_SLOTS,
|
|
8
|
+
ChannelsCard,
|
|
9
|
+
CrmList,
|
|
10
|
+
CrmShell,
|
|
11
|
+
CrmWorkspace,
|
|
12
|
+
FieldsForm,
|
|
13
|
+
IdentityCard,
|
|
14
|
+
RESERVED_FIELDS,
|
|
15
|
+
RecordPanel,
|
|
16
|
+
StageControl,
|
|
17
|
+
TagEditor,
|
|
18
|
+
ViewEditor,
|
|
19
|
+
useCrmQuery
|
|
20
|
+
} from "../chunk-7LH3WGSU.js";
|
|
21
|
+
|
|
22
|
+
// src/gallery/console.tsx
|
|
23
|
+
import { useMemo, useState } from "preact/hooks";
|
|
24
|
+
|
|
25
|
+
// src/client.ts
|
|
26
|
+
var CrmClientError = class extends Error {
|
|
27
|
+
status;
|
|
28
|
+
fields;
|
|
29
|
+
constructor(status, message, fields) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "CrmClientError";
|
|
32
|
+
this.status = status;
|
|
33
|
+
this.fields = fields;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var CrmClient = class {
|
|
37
|
+
base;
|
|
38
|
+
doFetch;
|
|
39
|
+
headers;
|
|
40
|
+
constructor(options = {}) {
|
|
41
|
+
this.base = `${options.baseUrl ?? ""}${options.basePath ?? "/api/crm"}`;
|
|
42
|
+
this.doFetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
43
|
+
this.headers = options.headers;
|
|
44
|
+
}
|
|
45
|
+
async request(method, path, body) {
|
|
46
|
+
const headers = { ...await this.headers?.() };
|
|
47
|
+
if (body !== void 0) headers["content-type"] = "application/json";
|
|
48
|
+
const response = await this.doFetch(`${this.base}${path}`, {
|
|
49
|
+
method,
|
|
50
|
+
headers,
|
|
51
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
52
|
+
});
|
|
53
|
+
const payload = await response.json().catch(() => ({}));
|
|
54
|
+
if (!response.ok)
|
|
55
|
+
throw new CrmClientError(
|
|
56
|
+
response.status,
|
|
57
|
+
typeof payload["error"] === "string" ? payload["error"] : `HTTP ${response.status}`,
|
|
58
|
+
payload["fields"]
|
|
59
|
+
);
|
|
60
|
+
return payload;
|
|
61
|
+
}
|
|
62
|
+
listRecords(params) {
|
|
63
|
+
const q = new URLSearchParams({ type: params.type });
|
|
64
|
+
if (params.search) q.set("search", params.search);
|
|
65
|
+
if (params.stage?.length) q.set("stage", params.stage.join(","));
|
|
66
|
+
if (params.emailStatus?.length) q.set("emailStatus", params.emailStatus.join(","));
|
|
67
|
+
if (params.billingStatus?.length) q.set("billingStatus", params.billingStatus.join(","));
|
|
68
|
+
if (params.ownerId) q.set("ownerId", params.ownerId);
|
|
69
|
+
if (params.tag) q.set("tag", params.tag);
|
|
70
|
+
if (params.archived) q.set("archived", "true");
|
|
71
|
+
if (params.sort) q.set("sort", `${params.sort.field}:${params.sort.dir}`);
|
|
72
|
+
if (params.limit != null) q.set("limit", String(params.limit));
|
|
73
|
+
if (params.offset != null) q.set("offset", String(params.offset));
|
|
74
|
+
if (params.fields) q.set("fields", JSON.stringify(params.fields));
|
|
75
|
+
return this.request("GET", `/records?${q}`);
|
|
76
|
+
}
|
|
77
|
+
getRecord(id) {
|
|
78
|
+
return this.request("GET", `/records/${encodeURIComponent(id)}`);
|
|
79
|
+
}
|
|
80
|
+
createRecord(body) {
|
|
81
|
+
return this.request("POST", "/records", body);
|
|
82
|
+
}
|
|
83
|
+
updateRecord(id, body) {
|
|
84
|
+
return this.request("PATCH", `/records/${encodeURIComponent(id)}`, body);
|
|
85
|
+
}
|
|
86
|
+
setArchived(id, archived) {
|
|
87
|
+
return this.request("POST", `/records/${encodeURIComponent(id)}/archive`, { archived });
|
|
88
|
+
}
|
|
89
|
+
setStage(id, to, mutationId) {
|
|
90
|
+
return this.request("POST", `/records/${encodeURIComponent(id)}/stage`, { to, mutationId });
|
|
91
|
+
}
|
|
92
|
+
setRank(id, body) {
|
|
93
|
+
return this.request("POST", `/records/${encodeURIComponent(id)}/rank`, body);
|
|
94
|
+
}
|
|
95
|
+
addTag(id, tag) {
|
|
96
|
+
return this.request("POST", `/records/${encodeURIComponent(id)}/tags`, { tag });
|
|
97
|
+
}
|
|
98
|
+
removeTag(id, tag) {
|
|
99
|
+
return this.request(
|
|
100
|
+
"DELETE",
|
|
101
|
+
`/records/${encodeURIComponent(id)}/tags/${encodeURIComponent(tag)}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
setLink(id, body) {
|
|
105
|
+
return this.request("POST", `/records/${encodeURIComponent(id)}/links`, body);
|
|
106
|
+
}
|
|
107
|
+
linkIdentity(id, email) {
|
|
108
|
+
return this.request("POST", `/records/${encodeURIComponent(id)}/link-identity`, { email });
|
|
109
|
+
}
|
|
110
|
+
sendEmail(id, body) {
|
|
111
|
+
return this.request("POST", `/records/${encodeURIComponent(id)}/email`, body);
|
|
112
|
+
}
|
|
113
|
+
listActivities(recordId, opts = {}) {
|
|
114
|
+
const q = new URLSearchParams();
|
|
115
|
+
if (opts.kind) q.set("kind", opts.kind);
|
|
116
|
+
if (opts.limit != null) q.set("limit", String(opts.limit));
|
|
117
|
+
return this.request("GET", `/records/${encodeURIComponent(recordId)}/activities?${q}`);
|
|
118
|
+
}
|
|
119
|
+
addActivity(recordId, body) {
|
|
120
|
+
return this.request("POST", `/records/${encodeURIComponent(recordId)}/activities`, body);
|
|
121
|
+
}
|
|
122
|
+
updateTask(id, body) {
|
|
123
|
+
return this.request("PATCH", `/activities/${encodeURIComponent(id)}`, body);
|
|
124
|
+
}
|
|
125
|
+
listTasks(opts = {}) {
|
|
126
|
+
const q = new URLSearchParams();
|
|
127
|
+
if (opts.assigneeId) q.set("assigneeId", opts.assigneeId);
|
|
128
|
+
if (opts.status?.length) q.set("status", opts.status.join(","));
|
|
129
|
+
if (opts.limit != null) q.set("limit", String(opts.limit));
|
|
130
|
+
return this.request("GET", `/tasks?${q}`);
|
|
131
|
+
}
|
|
132
|
+
listViews(type) {
|
|
133
|
+
return this.request("GET", `/views${type ? `?type=${encodeURIComponent(type)}` : ""}`);
|
|
134
|
+
}
|
|
135
|
+
saveView(spec) {
|
|
136
|
+
return this.request("POST", "/views", { spec });
|
|
137
|
+
}
|
|
138
|
+
updateView(id, spec) {
|
|
139
|
+
return this.request("PATCH", `/views/${encodeURIComponent(id)}`, { spec });
|
|
140
|
+
}
|
|
141
|
+
deleteView(id) {
|
|
142
|
+
return this.request("DELETE", `/views/${encodeURIComponent(id)}`);
|
|
143
|
+
}
|
|
144
|
+
summary(type) {
|
|
145
|
+
return this.request("GET", `/summary?type=${encodeURIComponent(type)}`);
|
|
146
|
+
}
|
|
147
|
+
getConfig() {
|
|
148
|
+
return this.request("GET", "/config");
|
|
149
|
+
}
|
|
150
|
+
saveConfig(patch) {
|
|
151
|
+
return this.request("PUT", "/config", patch);
|
|
152
|
+
}
|
|
153
|
+
emailLog(opts = {}) {
|
|
154
|
+
const q = new URLSearchParams();
|
|
155
|
+
if (opts.recordId) q.set("recordId", opts.recordId);
|
|
156
|
+
if (opts.limit != null) q.set("limit", String(opts.limit));
|
|
157
|
+
return this.request("GET", `/email-log?${q}`);
|
|
158
|
+
}
|
|
159
|
+
rebalance(type) {
|
|
160
|
+
return this.request("POST", "/rank/rebalance", { type });
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/errors.ts
|
|
165
|
+
var CrmInputError = class extends Error {
|
|
166
|
+
fields;
|
|
167
|
+
constructor(message, fields) {
|
|
168
|
+
super(message);
|
|
169
|
+
this.name = "CrmInputError";
|
|
170
|
+
this.fields = fields;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/rules.ts
|
|
175
|
+
var DENY = { view: "false", create: "false", update: "false", delete: "false" };
|
|
176
|
+
var CRM_RULES = Object.fromEntries(
|
|
177
|
+
Object.values(CRM_NS).map((ns) => [ns, { ...DENY }])
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// src/pipeline.ts
|
|
181
|
+
function initialStage(def) {
|
|
182
|
+
return def.pipeline?.stages[0]?.id;
|
|
183
|
+
}
|
|
184
|
+
function stageIndexOf(def, stage) {
|
|
185
|
+
const at = (def.pipeline?.stages ?? []).findIndex((s) => s.id === stage);
|
|
186
|
+
if (at === -1) throw new CrmInputError(`unknown stage "${stage}"`);
|
|
187
|
+
return at;
|
|
188
|
+
}
|
|
189
|
+
function canTransition(def, record, to) {
|
|
190
|
+
const pipeline = def.pipeline;
|
|
191
|
+
if (!pipeline) return "type has no pipeline";
|
|
192
|
+
const stages = new Map(pipeline.stages.map((s) => [s.id, s]));
|
|
193
|
+
if (!stages.has(to)) return `unknown stage "${to}"`;
|
|
194
|
+
const from = record.stage;
|
|
195
|
+
if (from === to) return "already in that stage";
|
|
196
|
+
if (from != null) {
|
|
197
|
+
if (!stages.has(from)) return `record is in unknown stage "${from}"`;
|
|
198
|
+
const declared = pipeline.transitions?.[from];
|
|
199
|
+
if (declared) {
|
|
200
|
+
if (!declared.includes(to)) return `cannot move from "${from}" to "${to}"`;
|
|
201
|
+
} else if (stages.get(from)?.terminal) {
|
|
202
|
+
return `"${from}" is terminal`;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const gate = pipeline.gates?.[to];
|
|
206
|
+
if (gate) {
|
|
207
|
+
const blocked = gate(record);
|
|
208
|
+
if (blocked) return blocked;
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/template.ts
|
|
214
|
+
var TOKEN_RE = /\{\{\s*([a-zA-Z][a-zA-Z0-9_]*)\s*\}\}/g;
|
|
215
|
+
function templateVars(template) {
|
|
216
|
+
const seen = /* @__PURE__ */ new Set();
|
|
217
|
+
for (const match of template.matchAll(TOKEN_RE)) seen.add(match[1]);
|
|
218
|
+
return [...seen];
|
|
219
|
+
}
|
|
220
|
+
function lintTemplate(template, knownVars) {
|
|
221
|
+
const used = templateVars(template);
|
|
222
|
+
const known = new Set(knownVars);
|
|
223
|
+
return {
|
|
224
|
+
unknown: used.filter((v) => !known.has(v)),
|
|
225
|
+
unused: knownVars.filter((v) => !used.includes(v))
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/field-conditions.ts
|
|
230
|
+
import { Environment, ParseError } from "@marcbachmann/cel-js";
|
|
231
|
+
var env = new Environment({ unlistedVariablesAreDyn: true });
|
|
232
|
+
function assertFieldCondition(expression, label) {
|
|
233
|
+
try {
|
|
234
|
+
env.evaluate(expression, { values: {} });
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (error instanceof ParseError) {
|
|
237
|
+
throw new Error(`${label}: not a valid CEL condition \u2014 ${error.message}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/validate.ts
|
|
243
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
244
|
+
var STRINGISH = /* @__PURE__ */ new Set(["string", "email", "url", "enum"]);
|
|
245
|
+
var bad = (error) => ({ ok: false, error });
|
|
246
|
+
var good = (value) => ({ ok: true, value });
|
|
247
|
+
function coerce(def, raw) {
|
|
248
|
+
if (raw === null) return good(null);
|
|
249
|
+
switch (def.type) {
|
|
250
|
+
case "string":
|
|
251
|
+
return typeof raw === "string" ? good(raw.trim()) : bad("expected a string");
|
|
252
|
+
case "email": {
|
|
253
|
+
if (typeof raw !== "string") return bad("expected an email address");
|
|
254
|
+
const email = raw.trim().toLowerCase();
|
|
255
|
+
return EMAIL_RE.test(email) ? good(email) : bad("not a valid email address");
|
|
256
|
+
}
|
|
257
|
+
case "url": {
|
|
258
|
+
if (typeof raw !== "string") return bad("expected a URL");
|
|
259
|
+
const url = raw.trim();
|
|
260
|
+
try {
|
|
261
|
+
const parsed = new URL(url);
|
|
262
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
263
|
+
return bad("must be an http(s) URL");
|
|
264
|
+
return good(url);
|
|
265
|
+
} catch {
|
|
266
|
+
return bad("not a valid URL");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
case "number":
|
|
270
|
+
return typeof raw === "number" && Number.isFinite(raw) ? good(raw) : bad("expected a number");
|
|
271
|
+
case "boolean":
|
|
272
|
+
return typeof raw === "boolean" ? good(raw) : bad("expected true or false");
|
|
273
|
+
case "date": {
|
|
274
|
+
if (typeof raw === "number" && Number.isFinite(raw)) return good(raw);
|
|
275
|
+
if (typeof raw === "string") {
|
|
276
|
+
const t = Date.parse(raw);
|
|
277
|
+
if (!Number.isNaN(t)) return good(t);
|
|
278
|
+
}
|
|
279
|
+
return bad("expected epoch ms or an ISO date string");
|
|
280
|
+
}
|
|
281
|
+
case "enum":
|
|
282
|
+
return typeof raw === "string" && (def.options ?? []).includes(raw) ? good(raw) : bad(`expected one of: ${(def.options ?? []).join(", ")}`);
|
|
283
|
+
case "json":
|
|
284
|
+
return raw === void 0 ? bad("expected a value") : good(raw);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
var empty = (def, value) => value == null || STRINGISH.has(def.type) && value === "";
|
|
288
|
+
function searchTextFor(def, name, email, fields) {
|
|
289
|
+
const parts = [name];
|
|
290
|
+
if (email) parts.push(email);
|
|
291
|
+
for (const [fieldName, field] of Object.entries(def.fields)) {
|
|
292
|
+
if (fieldName === (def.nameField ?? "name") || fieldName === def.emailField) continue;
|
|
293
|
+
const searchable = field.search ?? STRINGISH.has(field.type);
|
|
294
|
+
const value = fields[fieldName];
|
|
295
|
+
if (searchable && value != null && value !== "") parts.push(String(value));
|
|
296
|
+
}
|
|
297
|
+
return parts.join(" ").toLowerCase();
|
|
298
|
+
}
|
|
299
|
+
function prepare(def, input, existing) {
|
|
300
|
+
const errors = {};
|
|
301
|
+
for (const key of Object.keys(input))
|
|
302
|
+
if (!def.fields[key]) errors[key] = "unknown field";
|
|
303
|
+
const fields = { ...existing?.fields ?? {} };
|
|
304
|
+
for (const [fieldName, field] of Object.entries(def.fields)) {
|
|
305
|
+
const supplied = Object.hasOwn(input, fieldName);
|
|
306
|
+
if (supplied) {
|
|
307
|
+
const coerced = coerce(field, input[fieldName]);
|
|
308
|
+
if (!coerced.ok) {
|
|
309
|
+
errors[fieldName] = coerced.error;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
fields[fieldName] = coerced.value;
|
|
313
|
+
}
|
|
314
|
+
const settled = fields[fieldName];
|
|
315
|
+
if (field.required && (existing ? supplied || !(fieldName in fields) : true) && empty(field, settled))
|
|
316
|
+
errors[fieldName] = errors[fieldName] ?? "required";
|
|
317
|
+
}
|
|
318
|
+
const nameField = def.nameField ?? "name";
|
|
319
|
+
const name = fields[nameField];
|
|
320
|
+
if (typeof name !== "string" || name === "") errors[nameField] = errors[nameField] ?? "required";
|
|
321
|
+
let primaryEmail = null;
|
|
322
|
+
if (def.emailField) {
|
|
323
|
+
const email = fields[def.emailField];
|
|
324
|
+
primaryEmail = typeof email === "string" && email !== "" ? email : null;
|
|
325
|
+
}
|
|
326
|
+
if (Object.keys(errors).length > 0) return { ok: false, errors };
|
|
327
|
+
const attrs = {
|
|
328
|
+
name,
|
|
329
|
+
fields,
|
|
330
|
+
searchText: searchTextFor(def, name, primaryEmail, fields)
|
|
331
|
+
};
|
|
332
|
+
const retract = [];
|
|
333
|
+
const clear = (column) => {
|
|
334
|
+
if (existing) retract.push(column);
|
|
335
|
+
};
|
|
336
|
+
if (def.emailField) {
|
|
337
|
+
if (primaryEmail === null) clear("primaryEmail");
|
|
338
|
+
else attrs.primaryEmail = primaryEmail;
|
|
339
|
+
}
|
|
340
|
+
for (const [fieldName, field] of Object.entries(def.fields)) {
|
|
341
|
+
if (!field.slot) continue;
|
|
342
|
+
const value = fields[fieldName];
|
|
343
|
+
if (empty(field, value)) clear(field.slot);
|
|
344
|
+
else attrs[field.slot] = value;
|
|
345
|
+
}
|
|
346
|
+
return { ok: true, attrs, retract };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/config.ts
|
|
350
|
+
var NAME_RE = /^[a-z][a-z0-9_-]*$/;
|
|
351
|
+
var FIELD_RE = /^[a-z][a-zA-Z0-9_]*$/;
|
|
352
|
+
var SLOT_KIND = {
|
|
353
|
+
s1: ["string", "email", "url", "enum"],
|
|
354
|
+
s2: ["string", "email", "url", "enum"],
|
|
355
|
+
s3: ["string", "email", "url", "enum"],
|
|
356
|
+
s4: ["string", "email", "url", "enum"],
|
|
357
|
+
n1: ["number"],
|
|
358
|
+
n2: ["number"],
|
|
359
|
+
n3: ["number"],
|
|
360
|
+
d1: ["date"],
|
|
361
|
+
d2: ["date"]
|
|
362
|
+
};
|
|
363
|
+
function fail(path, message) {
|
|
364
|
+
throw new Error(`defineCrm: ${path} ${message}`);
|
|
365
|
+
}
|
|
366
|
+
function checkType(typeName, def) {
|
|
367
|
+
const at = `types.${typeName}`;
|
|
368
|
+
if (!NAME_RE.test(typeName)) fail(at, "must match /^[a-z][a-z0-9_-]*$/");
|
|
369
|
+
if (def.workspace != null && !NAME_RE.test(def.workspace)) {
|
|
370
|
+
fail(`${at}.workspace`, "must match /^[a-z][a-z0-9_-]*$/");
|
|
371
|
+
}
|
|
372
|
+
const claimed = /* @__PURE__ */ new Map();
|
|
373
|
+
for (const [fieldName, field] of Object.entries(def.fields)) {
|
|
374
|
+
const fat = `${at}.fields.${fieldName}`;
|
|
375
|
+
if (RESERVED_FIELDS.has(fieldName)) fail(fat, "is a reserved column name");
|
|
376
|
+
if (!FIELD_RE.test(fieldName)) fail(fat, "must match /^[a-z][a-zA-Z0-9_]*$/");
|
|
377
|
+
if (field.type === "enum" && !(field.options && field.options.length > 0))
|
|
378
|
+
fail(fat, "enum fields need non-empty options");
|
|
379
|
+
if (field.type !== "enum" && field.options) fail(fat, "options are for enum fields only");
|
|
380
|
+
for (const key of ["visibleWhen", "requiredWhen"]) {
|
|
381
|
+
const expression = field[key];
|
|
382
|
+
if (expression === void 0) continue;
|
|
383
|
+
if (typeof expression !== "string" || !expression.trim()) {
|
|
384
|
+
fail(`${fat}.${key}`, "must be a non-empty CEL condition");
|
|
385
|
+
}
|
|
386
|
+
try {
|
|
387
|
+
assertFieldCondition(expression, `${fat}.${key}`);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
fail(`${fat}.${key}`, error instanceof Error ? error.message : "invalid condition");
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (field.slot) {
|
|
393
|
+
if (!CRM_SLOTS.includes(field.slot)) fail(fat, `unknown slot ${field.slot}`);
|
|
394
|
+
if (!SLOT_KIND[field.slot].includes(field.type))
|
|
395
|
+
fail(fat, `slot ${field.slot} cannot hold a ${field.type} field`);
|
|
396
|
+
const holder = claimed.get(field.slot);
|
|
397
|
+
if (holder) fail(fat, `slot ${field.slot} already claimed by ${holder}`);
|
|
398
|
+
claimed.set(field.slot, fieldName);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const nameField = def.nameField ?? "name";
|
|
402
|
+
if (!def.fields[nameField]) fail(at, `nameField "${nameField}" is not a declared field`);
|
|
403
|
+
if (def.emailField) {
|
|
404
|
+
const emailDef = def.fields[def.emailField];
|
|
405
|
+
if (!emailDef) fail(at, `emailField "${def.emailField}" is not a declared field`);
|
|
406
|
+
if (emailDef.type !== "email") fail(at, `emailField "${def.emailField}" must have type "email"`);
|
|
407
|
+
}
|
|
408
|
+
checkPipeline(at, def);
|
|
409
|
+
}
|
|
410
|
+
function checkPipeline(at, def) {
|
|
411
|
+
const pipeline = def.pipeline;
|
|
412
|
+
if (!pipeline) return;
|
|
413
|
+
if (pipeline.stages.length === 0) fail(at, "pipeline.stages must not be empty");
|
|
414
|
+
const ids = /* @__PURE__ */ new Set();
|
|
415
|
+
for (const stage of pipeline.stages) {
|
|
416
|
+
if (ids.has(stage.id)) fail(at, `duplicate stage "${stage.id}"`);
|
|
417
|
+
ids.add(stage.id);
|
|
418
|
+
}
|
|
419
|
+
for (const [from, targets] of Object.entries(pipeline.transitions ?? {})) {
|
|
420
|
+
if (!ids.has(from)) fail(at, `transitions from unknown stage "${from}"`);
|
|
421
|
+
for (const to of targets) if (!ids.has(to)) fail(at, `transition to unknown stage "${to}"`);
|
|
422
|
+
}
|
|
423
|
+
for (const gated of Object.keys(pipeline.gates ?? {}))
|
|
424
|
+
if (!ids.has(gated)) fail(at, `gate on unknown stage "${gated}"`);
|
|
425
|
+
for (const hooked of Object.keys(def.onTransition ?? {}))
|
|
426
|
+
if (!ids.has(hooked)) fail(at, `onTransition hook on unknown stage "${hooked}"`);
|
|
427
|
+
}
|
|
428
|
+
function defineCrm(config) {
|
|
429
|
+
if (Object.keys(config.types).length === 0) fail("types", "must declare at least one type");
|
|
430
|
+
for (const [typeName, def] of Object.entries(config.types)) checkType(typeName, def);
|
|
431
|
+
for (const [relName, rel] of Object.entries(config.relations ?? {})) {
|
|
432
|
+
const at = `relations.${relName}`;
|
|
433
|
+
if (!config.types[rel.from]) fail(at, `unknown from-type "${rel.from}"`);
|
|
434
|
+
if (!config.types[rel.to]) fail(at, `unknown to-type "${rel.to}"`);
|
|
435
|
+
if (!rel.label) fail(at, "needs a label");
|
|
436
|
+
}
|
|
437
|
+
for (const [tplName, tpl] of Object.entries(config.templates ?? {})) {
|
|
438
|
+
const at = `templates.${tplName}`;
|
|
439
|
+
if (tpl.class !== "transactional" && tpl.class !== "marketing")
|
|
440
|
+
fail(at, `class must be transactional|marketing`);
|
|
441
|
+
for (const v of tpl.vars) if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(v)) fail(at, `bad var "${v}"`);
|
|
442
|
+
if (tpl.defaults) {
|
|
443
|
+
const lint = lintTemplate(`${tpl.defaults.subject}
|
|
444
|
+
${tpl.defaults.text}`, tpl.vars);
|
|
445
|
+
if (lint.unknown.length) fail(at, `defaults reference unknown vars: ${lint.unknown.join(", ")}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const type = (name) => {
|
|
449
|
+
const def = config.types[name];
|
|
450
|
+
if (!def) throw new CrmInputError(`unknown record type "${name}"`);
|
|
451
|
+
return def;
|
|
452
|
+
};
|
|
453
|
+
return {
|
|
454
|
+
config,
|
|
455
|
+
schema: CRM_SCHEMA,
|
|
456
|
+
rules: CRM_RULES,
|
|
457
|
+
type,
|
|
458
|
+
prepare: (name, input, existing) => prepare(type(name), input, existing),
|
|
459
|
+
canTransition: (name, record, to) => canTransition(type(name), record, to),
|
|
460
|
+
initialStage: (name) => initialStage(type(name)),
|
|
461
|
+
stageIndex: (name, stage) => stageIndexOf(type(name), stage)
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// src/gallery/demo-data.ts
|
|
466
|
+
var DEMO_NOW = 1755e9;
|
|
467
|
+
var day = 864e5;
|
|
468
|
+
var demoCrm = defineCrm({
|
|
469
|
+
types: {
|
|
470
|
+
person: {
|
|
471
|
+
label: "Person",
|
|
472
|
+
labelPlural: "People",
|
|
473
|
+
emailField: "email",
|
|
474
|
+
fields: {
|
|
475
|
+
name: { type: "string", required: true },
|
|
476
|
+
email: { type: "email" },
|
|
477
|
+
city: { type: "enum", options: ["Austin", "Chicago", "Portland"], slot: "s1" },
|
|
478
|
+
checkSize: { type: "number", slot: "n1" },
|
|
479
|
+
appliedAt: { type: "date", slot: "d1" },
|
|
480
|
+
accredited: { type: "boolean" }
|
|
481
|
+
},
|
|
482
|
+
pipeline: {
|
|
483
|
+
stages: [
|
|
484
|
+
{ id: "applied" },
|
|
485
|
+
{ id: "screening" },
|
|
486
|
+
{ id: "interviewed" },
|
|
487
|
+
{ id: "member", terminal: true },
|
|
488
|
+
{ id: "declined", terminal: true }
|
|
489
|
+
],
|
|
490
|
+
transitions: {
|
|
491
|
+
applied: ["screening", "declined"],
|
|
492
|
+
screening: ["interviewed", "declined"],
|
|
493
|
+
interviewed: ["member", "declined"]
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
facets: { identity: true, email: true }
|
|
497
|
+
},
|
|
498
|
+
company: {
|
|
499
|
+
label: "Company",
|
|
500
|
+
labelPlural: "Companies",
|
|
501
|
+
fields: {
|
|
502
|
+
name: { type: "string", required: true },
|
|
503
|
+
sector: { type: "enum", options: ["Climate", "Health", "Industrial"], slot: "s1" }
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
relations: {
|
|
508
|
+
worksAt: { from: "person", to: "company", label: "Works at" }
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
var person = (id, name, stage, stageIndex, city, checkSize, extra = {}) => ({
|
|
512
|
+
id,
|
|
513
|
+
type: "person",
|
|
514
|
+
name,
|
|
515
|
+
primaryEmail: `${id}@example.com`,
|
|
516
|
+
stage,
|
|
517
|
+
stageIndex,
|
|
518
|
+
stageChangedAt: DEMO_NOW - stageIndex * day,
|
|
519
|
+
emailStatus: "ok",
|
|
520
|
+
s1: city,
|
|
521
|
+
n1: checkSize,
|
|
522
|
+
d1: DEMO_NOW - 30 * day,
|
|
523
|
+
fields: { name, email: `${id}@example.com`, city, checkSize, accredited: true },
|
|
524
|
+
searchText: `${name} ${city}`.toLowerCase(),
|
|
525
|
+
archived: false,
|
|
526
|
+
createdAt: DEMO_NOW - 40 * day,
|
|
527
|
+
updatedAt: DEMO_NOW - stageIndex * day,
|
|
528
|
+
...extra
|
|
529
|
+
});
|
|
530
|
+
var demoRecords = [
|
|
531
|
+
person("avery", "Avery Chen", "interviewed", 2, "Austin", 25e3, { clerkUserId: "user_2f1c" }),
|
|
532
|
+
person("bo", "Bo Ramirez", "screening", 1, "Chicago", 1e4),
|
|
533
|
+
person("cyn", "Cyn Okafor", "member", 3, "Portland", 5e4, { clerkUserId: "user_9a4d" }),
|
|
534
|
+
person("dara", "Dara Lindqvist", "applied", 0, "Austin", 5e3),
|
|
535
|
+
person("emi", "Emi Tanaka", "screening", 1, "Portland", 15e3),
|
|
536
|
+
person("fenn", "Fenn Alvarez", "applied", 0, "Chicago", 2e4)
|
|
537
|
+
];
|
|
538
|
+
var demoTags = {
|
|
539
|
+
avery: [
|
|
540
|
+
{ id: "t1", key: "avery:warm", recordId: "avery", tag: "warm", createdAt: DEMO_NOW - 5 * day },
|
|
541
|
+
{ id: "t2", key: "avery:referral", recordId: "avery", tag: "referral", createdAt: DEMO_NOW - 5 * day }
|
|
542
|
+
]
|
|
543
|
+
};
|
|
544
|
+
var demoChannels = {
|
|
545
|
+
avery: [
|
|
546
|
+
{
|
|
547
|
+
id: "c1",
|
|
548
|
+
key: "avery:email:avery@example.com",
|
|
549
|
+
recordId: "avery",
|
|
550
|
+
kind: "email",
|
|
551
|
+
value: "avery@example.com",
|
|
552
|
+
isPrimary: true,
|
|
553
|
+
consent: "subscribed",
|
|
554
|
+
consentAt: DEMO_NOW - 30 * day,
|
|
555
|
+
consentSource: "application form",
|
|
556
|
+
unsubscribeToken: "demo-token",
|
|
557
|
+
createdAt: DEMO_NOW - 30 * day
|
|
558
|
+
}
|
|
559
|
+
]
|
|
560
|
+
};
|
|
561
|
+
var demoActivities = [
|
|
562
|
+
{
|
|
563
|
+
id: "a1",
|
|
564
|
+
recordId: "avery",
|
|
565
|
+
kind: "note",
|
|
566
|
+
body: "Intro call went well \u2014 wants to co-invest alongside the syndicate.",
|
|
567
|
+
authorId: "admin-1",
|
|
568
|
+
createdAt: DEMO_NOW - 2 * day
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
id: "a2",
|
|
572
|
+
recordId: "avery",
|
|
573
|
+
kind: "task",
|
|
574
|
+
body: "Send the diligence packet",
|
|
575
|
+
status: "open",
|
|
576
|
+
dueAt: DEMO_NOW + 2 * day,
|
|
577
|
+
authorId: "admin-1",
|
|
578
|
+
createdAt: DEMO_NOW - day
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
id: "a3",
|
|
582
|
+
recordId: "avery",
|
|
583
|
+
kind: "stage_change",
|
|
584
|
+
body: "screening \u2192 interviewed",
|
|
585
|
+
authorId: "admin-1",
|
|
586
|
+
createdAt: DEMO_NOW - 2 * day
|
|
587
|
+
}
|
|
588
|
+
];
|
|
589
|
+
var demoViews = [
|
|
590
|
+
{
|
|
591
|
+
id: "v-austin",
|
|
592
|
+
name: "Austin pipeline",
|
|
593
|
+
type: "person",
|
|
594
|
+
ownerId: "admin-1",
|
|
595
|
+
shared: false,
|
|
596
|
+
filters: { fields: { city: { eq: "Austin" } } },
|
|
597
|
+
sort: { field: "name", dir: "asc" },
|
|
598
|
+
columns: ["name", "stage", "city"],
|
|
599
|
+
createdAt: DEMO_NOW - 10 * day,
|
|
600
|
+
updatedAt: DEMO_NOW - 10 * day
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
id: "v-large",
|
|
604
|
+
name: "Large checks",
|
|
605
|
+
type: "person",
|
|
606
|
+
shared: true,
|
|
607
|
+
filters: {},
|
|
608
|
+
sort: { field: "checkSize", dir: "desc" },
|
|
609
|
+
columns: ["name", "checkSize"],
|
|
610
|
+
createdAt: DEMO_NOW - 20 * day,
|
|
611
|
+
updatedAt: DEMO_NOW - 20 * day
|
|
612
|
+
}
|
|
613
|
+
];
|
|
614
|
+
|
|
615
|
+
// src/gallery/demo-client.ts
|
|
616
|
+
var json = (body, status = 200) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
617
|
+
var sortValue = (record, field) => {
|
|
618
|
+
if (field === "name") return record.name;
|
|
619
|
+
if (field === "stage") return record.stageIndex ?? 0;
|
|
620
|
+
const promoted = record[field];
|
|
621
|
+
if (typeof promoted === "string" || typeof promoted === "number") return promoted;
|
|
622
|
+
const value = record.fields[field];
|
|
623
|
+
return typeof value === "string" || typeof value === "number" ? value : "";
|
|
624
|
+
};
|
|
625
|
+
function demoFetch() {
|
|
626
|
+
const records = demoRecords.map((record) => ({ ...record }));
|
|
627
|
+
const tags = Object.fromEntries(
|
|
628
|
+
Object.entries(demoTags).map(([id, list]) => [id, list.map((tag) => ({ ...tag }))])
|
|
629
|
+
);
|
|
630
|
+
const find = (id) => records.find((record) => record.id === id);
|
|
631
|
+
return async (input, init) => {
|
|
632
|
+
const href = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
633
|
+
const url = new URL(href, "https://demo.invalid");
|
|
634
|
+
const path = url.pathname.replace(/^\/api\/crm/, "");
|
|
635
|
+
const method = init?.method ?? "GET";
|
|
636
|
+
const body = init?.body ? JSON.parse(String(init.body)) : {};
|
|
637
|
+
if (method === "GET" && path === "/views") {
|
|
638
|
+
const type = url.searchParams.get("type");
|
|
639
|
+
return json({ views: demoViews.filter((view) => !type || view.type === type) });
|
|
640
|
+
}
|
|
641
|
+
if (method === "GET" && path === "/records") {
|
|
642
|
+
const type = url.searchParams.get("type") ?? "person";
|
|
643
|
+
const search = (url.searchParams.get("search") ?? "").toLowerCase();
|
|
644
|
+
const offset = Number(url.searchParams.get("offset") ?? 0);
|
|
645
|
+
const limit = Number(url.searchParams.get("limit") ?? 25);
|
|
646
|
+
const sort = url.searchParams.get("sort");
|
|
647
|
+
const dir = url.searchParams.get("dir") === "desc" ? -1 : 1;
|
|
648
|
+
let matched = records.filter(
|
|
649
|
+
(record) => record.type === type && (!search || record.searchText.includes(search))
|
|
650
|
+
);
|
|
651
|
+
if (sort) {
|
|
652
|
+
matched = [...matched].sort(
|
|
653
|
+
(a, b) => sortValue(a, sort) > sortValue(b, sort) ? dir : sortValue(a, sort) < sortValue(b, sort) ? -dir : 0
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
return json({ records: matched.slice(offset, offset + limit), total: matched.length, limit, offset });
|
|
657
|
+
}
|
|
658
|
+
const recordMatch = /^\/records\/([^/]+)(\/.*)?$/.exec(path);
|
|
659
|
+
if (recordMatch) {
|
|
660
|
+
const record = find(decodeURIComponent(recordMatch[1]));
|
|
661
|
+
if (!record) return json({ error: "not found" }, 404);
|
|
662
|
+
const rest = recordMatch[2] ?? "";
|
|
663
|
+
if (method === "GET" && !rest) {
|
|
664
|
+
return json({
|
|
665
|
+
record,
|
|
666
|
+
tags: tags[record.id] ?? [],
|
|
667
|
+
channels: demoChannels[record.id] ?? [],
|
|
668
|
+
links: []
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
if (method === "PATCH" && !rest) {
|
|
672
|
+
Object.assign(record.fields, body.input ?? {});
|
|
673
|
+
if (typeof record.fields.name === "string") record.name = record.fields.name;
|
|
674
|
+
record.updatedAt = DEMO_NOW;
|
|
675
|
+
return json({ record, duplicate: false });
|
|
676
|
+
}
|
|
677
|
+
if (method === "POST" && rest === "/stage") {
|
|
678
|
+
const from = record.stage ?? null;
|
|
679
|
+
record.stage = String(body.to);
|
|
680
|
+
record.stageChangedAt = DEMO_NOW;
|
|
681
|
+
return json({ record, from, duplicate: false });
|
|
682
|
+
}
|
|
683
|
+
if (method === "POST" && rest === "/tags") {
|
|
684
|
+
const tag = String(body.tag);
|
|
685
|
+
const list = tags[record.id] ??= [];
|
|
686
|
+
if (!list.some((existing) => existing.tag === tag)) {
|
|
687
|
+
list.push({
|
|
688
|
+
id: `demo-${tag}`,
|
|
689
|
+
key: `${record.id}:${tag}`,
|
|
690
|
+
recordId: record.id,
|
|
691
|
+
tag,
|
|
692
|
+
createdAt: DEMO_NOW
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
return json({ tag, duplicate: false });
|
|
696
|
+
}
|
|
697
|
+
const removal = /^\/tags\/(.+)$/.exec(rest);
|
|
698
|
+
if (method === "DELETE" && removal) {
|
|
699
|
+
const tag = decodeURIComponent(removal[1]);
|
|
700
|
+
tags[record.id] = (tags[record.id] ?? []).filter((existing) => existing.tag !== tag);
|
|
701
|
+
return json({ duplicate: false });
|
|
702
|
+
}
|
|
703
|
+
if (method === "POST" && rest === "/link-identity") {
|
|
704
|
+
record.clerkUserId = "user_demo";
|
|
705
|
+
return json({ linked: true, clerkUserId: record.clerkUserId });
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return json({ error: `the gallery fixture does not serve ${method} ${path}` }, 404);
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
var demoClient = () => new CrmClient({ fetch: demoFetch() });
|
|
712
|
+
|
|
713
|
+
// src/gallery/console.tsx
|
|
714
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
715
|
+
function ConsoleDemo({ withViews }) {
|
|
716
|
+
const client = useMemo(demoClient, []);
|
|
717
|
+
const [active, setActive] = useState({ type: "person" });
|
|
718
|
+
const [settings, setSettings] = useState(false);
|
|
719
|
+
const views = withViews ? demoViews.filter((view) => view.type === active.type) : [];
|
|
720
|
+
return /* @__PURE__ */ jsx(
|
|
721
|
+
CrmShell,
|
|
722
|
+
{
|
|
723
|
+
crm: demoCrm,
|
|
724
|
+
active,
|
|
725
|
+
views,
|
|
726
|
+
onNavigate: (target) => {
|
|
727
|
+
setSettings(false);
|
|
728
|
+
setActive(target);
|
|
729
|
+
},
|
|
730
|
+
onOpenSettings: () => setSettings(true),
|
|
731
|
+
children: settings ? /* @__PURE__ */ jsxs("div", { className: "panel", children: [
|
|
732
|
+
/* @__PURE__ */ jsx("h3", { style: { marginTop: 0 }, children: "Settings" }),
|
|
733
|
+
/* @__PURE__ */ jsx("p", { className: "muted", children: "The shell reports the intent; the route and the page are the host's." })
|
|
734
|
+
] }) : /* @__PURE__ */ jsx(CrmWorkspace, { crm: demoCrm, client, type: active.type })
|
|
735
|
+
}
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
var crmConsoleEntry = {
|
|
739
|
+
id: "crm-console",
|
|
740
|
+
group: "CRM",
|
|
741
|
+
title: "CRM console: left navigation + workspace",
|
|
742
|
+
description: "CrmShell's sidebar lists every configured record type, the active type's saved views, and Settings \u2014 around a CrmWorkspace. Navigation state is the host's; the shell only reports intent.",
|
|
743
|
+
presentation: "viewport",
|
|
744
|
+
kind: "component",
|
|
745
|
+
components: ["CrmShell"],
|
|
746
|
+
render: () => /* @__PURE__ */ jsx(ConsoleDemo, { withViews: true })
|
|
747
|
+
};
|
|
748
|
+
var crmConsoleBareEntry = {
|
|
749
|
+
id: "crm-console-no-views",
|
|
750
|
+
group: "CRM",
|
|
751
|
+
title: "Sidebar without saved views",
|
|
752
|
+
description: "The Views section does not render at all when the host passes none \u2014 a sidebar that looks like it lost its views is usually a listViews call that has not resolved.",
|
|
753
|
+
presentation: "viewport",
|
|
754
|
+
kind: "pattern",
|
|
755
|
+
render: () => /* @__PURE__ */ jsx(ConsoleDemo, { withViews: false })
|
|
756
|
+
};
|
|
757
|
+
function WorkspaceDemo({ collapse }) {
|
|
758
|
+
const client = useMemo(demoClient, []);
|
|
759
|
+
return /* @__PURE__ */ jsx(
|
|
760
|
+
CrmWorkspace,
|
|
761
|
+
{
|
|
762
|
+
crm: demoCrm,
|
|
763
|
+
client,
|
|
764
|
+
type: "person",
|
|
765
|
+
collapseClosedDetail: collapse,
|
|
766
|
+
renderSummary: ({ query }) => /* @__PURE__ */ jsxs("div", { className: "cards", style: { margin: 0 }, children: [
|
|
767
|
+
/* @__PURE__ */ jsxs("div", { className: "card", children: [
|
|
768
|
+
/* @__PURE__ */ jsx("h4", { children: "People" }),
|
|
769
|
+
/* @__PURE__ */ jsx("div", { className: "metric", children: query.page?.total ?? "\u2014" })
|
|
770
|
+
] }),
|
|
771
|
+
/* @__PURE__ */ jsxs("div", { className: "card", children: [
|
|
772
|
+
/* @__PURE__ */ jsx("h4", { children: "Interviewed" }),
|
|
773
|
+
/* @__PURE__ */ jsx("div", { className: "metric", children: "1" })
|
|
774
|
+
] })
|
|
775
|
+
] })
|
|
776
|
+
}
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
var crmWorkspaceEntry = {
|
|
780
|
+
id: "crm-workspace",
|
|
781
|
+
group: "CRM",
|
|
782
|
+
title: "Record workspace (master/detail)",
|
|
783
|
+
description: "The list keeps the full width until a record opens, then the detail pane takes its half. Selection, loading and mutation state stay inside the workspace \u2014 renderSummary and friends replace content, never pane geometry.",
|
|
784
|
+
presentation: "viewport",
|
|
785
|
+
kind: "component",
|
|
786
|
+
components: ["CrmWorkspace"],
|
|
787
|
+
render: () => /* @__PURE__ */ jsx(WorkspaceDemo, { collapse: true })
|
|
788
|
+
};
|
|
789
|
+
var crmWorkspaceSplitEntry = {
|
|
790
|
+
id: "crm-workspace-split",
|
|
791
|
+
group: "CRM",
|
|
792
|
+
title: "Workspace holding both panes open",
|
|
793
|
+
description: "collapseClosedDetail={false} keeps the two-pane geometry with nothing selected, which is what renderEmptyDetail is for.",
|
|
794
|
+
presentation: "viewport",
|
|
795
|
+
kind: "pattern",
|
|
796
|
+
render: () => /* @__PURE__ */ jsx(WorkspaceDemo, { collapse: false })
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// src/gallery/list.tsx
|
|
800
|
+
import { useMemo as useMemo2, useState as useState2 } from "preact/hooks";
|
|
801
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "preact/jsx-runtime";
|
|
802
|
+
function ListDemo({ selectable }) {
|
|
803
|
+
const client = useMemo2(demoClient, []);
|
|
804
|
+
const query = useCrmQuery(client, "person");
|
|
805
|
+
const [selected, setSelected] = useState2([]);
|
|
806
|
+
return /* @__PURE__ */ jsx2(
|
|
807
|
+
CrmList,
|
|
808
|
+
{
|
|
809
|
+
crm: demoCrm,
|
|
810
|
+
type: "person",
|
|
811
|
+
query,
|
|
812
|
+
selectable,
|
|
813
|
+
selected,
|
|
814
|
+
onSelectionChange: setSelected,
|
|
815
|
+
toolbar: selectable ? /* @__PURE__ */ jsx2(
|
|
816
|
+
BulkBar,
|
|
817
|
+
{
|
|
818
|
+
selected,
|
|
819
|
+
onClear: () => setSelected([]),
|
|
820
|
+
actions: [
|
|
821
|
+
{ id: "tag", label: "Tag", run: async () => {
|
|
822
|
+
} },
|
|
823
|
+
{ id: "archive", label: "Archive", run: async () => {
|
|
824
|
+
} }
|
|
825
|
+
]
|
|
826
|
+
}
|
|
827
|
+
) : void 0
|
|
828
|
+
}
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
var crmListEntry = {
|
|
832
|
+
id: "crm-list",
|
|
833
|
+
group: "CRM",
|
|
834
|
+
title: "Record list",
|
|
835
|
+
description: "Server-driven: sort clicks, the search box and the stage chips all move the query rather than filtering rows in the browser, so paging stays honest.",
|
|
836
|
+
kind: "component",
|
|
837
|
+
components: ["CrmList"],
|
|
838
|
+
render: () => /* @__PURE__ */ jsx2(ListDemo, { selectable: false })
|
|
839
|
+
};
|
|
840
|
+
var crmBulkEntry = {
|
|
841
|
+
id: "crm-bulk-bar",
|
|
842
|
+
group: "CRM",
|
|
843
|
+
title: "Selection + bulk actions",
|
|
844
|
+
description: "BulkBar renders nothing until something is selected, so the toolbar slot costs no vertical space at rest. Tick a row to raise it.",
|
|
845
|
+
kind: "component",
|
|
846
|
+
components: ["BulkBar"],
|
|
847
|
+
render: () => /* @__PURE__ */ jsx2(ListDemo, { selectable: true })
|
|
848
|
+
};
|
|
849
|
+
function ViewEditorDemo() {
|
|
850
|
+
const [saved, setSaved] = useState2(null);
|
|
851
|
+
return /* @__PURE__ */ jsxs2("div", { style: { display: "grid", gap: 12 }, children: [
|
|
852
|
+
/* @__PURE__ */ jsx2(
|
|
853
|
+
ViewEditor,
|
|
854
|
+
{
|
|
855
|
+
current: {
|
|
856
|
+
type: "person",
|
|
857
|
+
filters: { fields: { city: { eq: "Austin" } } },
|
|
858
|
+
sort: { field: "name", dir: "asc" },
|
|
859
|
+
columns: ["name", "stage"]
|
|
860
|
+
},
|
|
861
|
+
onSave: async (spec) => setSaved(`${spec.name}${spec.shared ? " (shared)" : ""}`)
|
|
862
|
+
}
|
|
863
|
+
),
|
|
864
|
+
saved && /* @__PURE__ */ jsxs2("p", { className: "muted", children: [
|
|
865
|
+
"Saved view: ",
|
|
866
|
+
saved
|
|
867
|
+
] })
|
|
868
|
+
] });
|
|
869
|
+
}
|
|
870
|
+
var crmViewEditorEntry = {
|
|
871
|
+
id: "crm-view-editor",
|
|
872
|
+
group: "CRM",
|
|
873
|
+
title: "Saved view editor",
|
|
874
|
+
description: "Snapshots the current filters, sort and columns under a name. Collapses back to a button once saved.",
|
|
875
|
+
kind: "component",
|
|
876
|
+
components: ["ViewEditor"],
|
|
877
|
+
render: () => /* @__PURE__ */ jsx2(ViewEditorDemo, {})
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
// src/gallery/record.tsx
|
|
881
|
+
import { useState as useState3 } from "preact/hooks";
|
|
882
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "preact/jsx-runtime";
|
|
883
|
+
var avery = demoRecords[0];
|
|
884
|
+
var detail = {
|
|
885
|
+
record: avery,
|
|
886
|
+
tags: demoTags.avery ?? [],
|
|
887
|
+
channels: demoChannels.avery ?? [],
|
|
888
|
+
links: []
|
|
889
|
+
};
|
|
890
|
+
function RecordPanelDemo({ stagePlacement }) {
|
|
891
|
+
const [tags, setTags] = useState3(detail.tags);
|
|
892
|
+
return /* @__PURE__ */ jsx3(
|
|
893
|
+
RecordPanel,
|
|
894
|
+
{
|
|
895
|
+
crm: demoCrm,
|
|
896
|
+
detail: { ...detail, tags },
|
|
897
|
+
stagePlacement,
|
|
898
|
+
onSaveFields: () => {
|
|
899
|
+
},
|
|
900
|
+
onMoveStage: async () => {
|
|
901
|
+
},
|
|
902
|
+
onAddTag: (tag) => setTags(
|
|
903
|
+
(current) => current.some((existing) => existing.tag === tag) ? current : [...current, { id: tag, key: `${avery.id}:${tag}`, recordId: avery.id, tag, createdAt: DEMO_NOW }]
|
|
904
|
+
),
|
|
905
|
+
onRemoveTag: (tag) => setTags((current) => current.filter((existing) => existing.tag !== tag)),
|
|
906
|
+
onLinkIdentity: () => {
|
|
907
|
+
},
|
|
908
|
+
activitySlot: /* @__PURE__ */ jsx3(
|
|
909
|
+
ActivityFeed,
|
|
910
|
+
{
|
|
911
|
+
activities: demoActivities,
|
|
912
|
+
onAddNote: () => {
|
|
913
|
+
},
|
|
914
|
+
onAddTask: () => {
|
|
915
|
+
},
|
|
916
|
+
onToggleTask: () => {
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
)
|
|
920
|
+
}
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
var crmRecordPanelEntry = {
|
|
924
|
+
id: "crm-record-panel",
|
|
925
|
+
group: "CRM",
|
|
926
|
+
title: "Record panel",
|
|
927
|
+
description: "Profile, activity and billing as tabs over one record, with tags and stage movement inline. This is what fills the workspace's detail pane.",
|
|
928
|
+
kind: "component",
|
|
929
|
+
components: ["RecordPanel"],
|
|
930
|
+
render: () => /* @__PURE__ */ jsx3(RecordPanelDemo, { stagePlacement: "tab" })
|
|
931
|
+
};
|
|
932
|
+
var crmRecordPanelHeaderEntry = {
|
|
933
|
+
id: "crm-record-panel-header-stage",
|
|
934
|
+
group: "CRM",
|
|
935
|
+
title: "Record panel with stage in the header",
|
|
936
|
+
description: 'stagePlacement="header" lifts pipeline movement out of the tab set, for consoles where moving a record is the main verb.',
|
|
937
|
+
kind: "pattern",
|
|
938
|
+
render: () => /* @__PURE__ */ jsx3(RecordPanelDemo, { stagePlacement: "header" })
|
|
939
|
+
};
|
|
940
|
+
var crmActivityEntry = {
|
|
941
|
+
id: "crm-activity-feed",
|
|
942
|
+
group: "CRM",
|
|
943
|
+
title: "Activity feed",
|
|
944
|
+
description: "Composer switching between note and task above a newest-first feed; stage moves land in the same timeline.",
|
|
945
|
+
kind: "component",
|
|
946
|
+
components: ["ActivityFeed"],
|
|
947
|
+
render: () => /* @__PURE__ */ jsx3(
|
|
948
|
+
ActivityFeed,
|
|
949
|
+
{
|
|
950
|
+
activities: demoActivities,
|
|
951
|
+
onAddNote: () => {
|
|
952
|
+
},
|
|
953
|
+
onAddTask: () => {
|
|
954
|
+
},
|
|
955
|
+
onToggleTask: () => {
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
)
|
|
959
|
+
};
|
|
960
|
+
var crmFormEntry = {
|
|
961
|
+
id: "crm-fields-form",
|
|
962
|
+
group: "CRM",
|
|
963
|
+
title: "Record form",
|
|
964
|
+
description: "Generated from the type's field definitions \u2014 one control per declared type, with the server's per-field 400 errors rendered inline.",
|
|
965
|
+
kind: "component",
|
|
966
|
+
components: ["FieldsForm"],
|
|
967
|
+
render: () => /* @__PURE__ */ jsxs3("div", { className: "demo-grid", children: [
|
|
968
|
+
/* @__PURE__ */ jsx3(FieldsForm, { crm: demoCrm, type: "person", onSubmit: () => {
|
|
969
|
+
}, submitLabel: "Create person" }),
|
|
970
|
+
/* @__PURE__ */ jsx3(
|
|
971
|
+
FieldsForm,
|
|
972
|
+
{
|
|
973
|
+
crm: demoCrm,
|
|
974
|
+
type: "person",
|
|
975
|
+
record: avery,
|
|
976
|
+
onSubmit: () => {
|
|
977
|
+
},
|
|
978
|
+
errors: { email: "That address is already on another record." },
|
|
979
|
+
submitLabel: "Save"
|
|
980
|
+
}
|
|
981
|
+
)
|
|
982
|
+
] })
|
|
983
|
+
};
|
|
984
|
+
function TagEditorDemo() {
|
|
985
|
+
const [tags, setTags] = useState3(detail.tags);
|
|
986
|
+
return /* @__PURE__ */ jsx3(
|
|
987
|
+
TagEditor,
|
|
988
|
+
{
|
|
989
|
+
tags,
|
|
990
|
+
onAdd: (tag) => setTags(
|
|
991
|
+
(current) => current.some((existing) => existing.tag === tag) ? current : [...current, { id: tag, key: `${avery.id}:${tag}`, recordId: avery.id, tag, createdAt: DEMO_NOW }]
|
|
992
|
+
),
|
|
993
|
+
onRemove: (tag) => setTags((current) => current.filter((existing) => existing.tag !== tag)),
|
|
994
|
+
suggest: () => [{ value: "warm" }, { value: "referral" }, { value: "syndicate" }]
|
|
995
|
+
}
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
var crmTagsEntry = {
|
|
999
|
+
id: "crm-tag-editor",
|
|
1000
|
+
group: "CRM",
|
|
1001
|
+
title: "Tag editor",
|
|
1002
|
+
description: "Chips plus a typeahead adder over the shared `.chips` contract.",
|
|
1003
|
+
kind: "component",
|
|
1004
|
+
components: ["TagEditor"],
|
|
1005
|
+
render: () => /* @__PURE__ */ jsx3(TagEditorDemo, {})
|
|
1006
|
+
};
|
|
1007
|
+
var crmStageEntry = {
|
|
1008
|
+
id: "crm-stage-control",
|
|
1009
|
+
group: "CRM",
|
|
1010
|
+
title: "Stage control",
|
|
1011
|
+
description: "Offers only the transitions the pipeline allows from where the record stands, and surfaces a rejected move inline. Renders nothing for a type with no pipeline.",
|
|
1012
|
+
kind: "component",
|
|
1013
|
+
components: ["StageControl"],
|
|
1014
|
+
render: () => /* @__PURE__ */ jsxs3("div", { className: "demo-grid", children: [
|
|
1015
|
+
/* @__PURE__ */ jsx3(StageControl, { crm: demoCrm, record: avery, onMove: async () => {
|
|
1016
|
+
} }),
|
|
1017
|
+
/* @__PURE__ */ jsx3(
|
|
1018
|
+
StageControl,
|
|
1019
|
+
{
|
|
1020
|
+
crm: demoCrm,
|
|
1021
|
+
record: avery,
|
|
1022
|
+
onMove: async () => {
|
|
1023
|
+
throw new Error("Needs a signed subscription agreement first.");
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
)
|
|
1027
|
+
] })
|
|
1028
|
+
};
|
|
1029
|
+
var crmCardsEntry = {
|
|
1030
|
+
id: "crm-facet-cards",
|
|
1031
|
+
group: "CRM",
|
|
1032
|
+
title: "Identity, billing and consent cards",
|
|
1033
|
+
description: "The facet cards: Clerk linkage, the billing cache an app-injected provider fills, and the truthful answer to whether you may email this person.",
|
|
1034
|
+
kind: "component",
|
|
1035
|
+
components: ["IdentityCard", "BillingCard", "ChannelsCard"],
|
|
1036
|
+
render: () => /* @__PURE__ */ jsxs3("div", { className: "demo-grid", children: [
|
|
1037
|
+
/* @__PURE__ */ jsx3(IdentityCard, { record: avery, onLink: () => {
|
|
1038
|
+
} }),
|
|
1039
|
+
/* @__PURE__ */ jsx3(IdentityCard, { record: demoRecords[3], onLink: () => {
|
|
1040
|
+
} }),
|
|
1041
|
+
/* @__PURE__ */ jsx3(
|
|
1042
|
+
BillingCard,
|
|
1043
|
+
{
|
|
1044
|
+
record: {
|
|
1045
|
+
...avery,
|
|
1046
|
+
stripeCustomerId: "cus_demo",
|
|
1047
|
+
billingStatus: "active",
|
|
1048
|
+
mrr: 8300,
|
|
1049
|
+
renewalAt: DEMO_NOW + 30 * 864e5
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
),
|
|
1053
|
+
/* @__PURE__ */ jsx3(ChannelsCard, { channels: detail.channels })
|
|
1054
|
+
] })
|
|
1055
|
+
};
|
|
1056
|
+
|
|
1057
|
+
// src/gallery/index.ts
|
|
1058
|
+
var CRM_GALLERY = [
|
|
1059
|
+
crmConsoleEntry,
|
|
1060
|
+
crmConsoleBareEntry,
|
|
1061
|
+
crmWorkspaceEntry,
|
|
1062
|
+
crmWorkspaceSplitEntry,
|
|
1063
|
+
crmListEntry,
|
|
1064
|
+
crmBulkEntry,
|
|
1065
|
+
crmViewEditorEntry,
|
|
1066
|
+
crmRecordPanelEntry,
|
|
1067
|
+
crmRecordPanelHeaderEntry,
|
|
1068
|
+
crmFormEntry,
|
|
1069
|
+
crmActivityEntry,
|
|
1070
|
+
crmTagsEntry,
|
|
1071
|
+
crmStageEntry,
|
|
1072
|
+
crmCardsEntry
|
|
1073
|
+
];
|
|
1074
|
+
export {
|
|
1075
|
+
CRM_GALLERY,
|
|
1076
|
+
demoClient,
|
|
1077
|
+
demoCrm,
|
|
1078
|
+
demoFetch
|
|
1079
|
+
};
|
|
1080
|
+
//# sourceMappingURL=index.js.map
|