@odla-ai/crm 0.7.0 → 0.8.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/dist/index.cjs +43 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/dist/ui/index.js +221 -2
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
package/dist/ui/index.js
CHANGED
|
@@ -76,6 +76,18 @@ function useCrmRecord(client, id) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/constants.ts
|
|
79
|
+
var CRM_NS = {
|
|
80
|
+
record: "crm_record",
|
|
81
|
+
tag: "crm_tag",
|
|
82
|
+
link: "crm_link",
|
|
83
|
+
activity: "crm_activity",
|
|
84
|
+
channel: "crm_contact_channel",
|
|
85
|
+
emailLog: "crm_email_log",
|
|
86
|
+
view: "crm_view",
|
|
87
|
+
config: "crm_config",
|
|
88
|
+
origin: "crm_record_origin",
|
|
89
|
+
delivery: "crm_record_delivery"
|
|
90
|
+
};
|
|
79
91
|
var CRM_SLOTS = ["s1", "s2", "s3", "s4", "n1", "n2", "n3", "d1", "d2"];
|
|
80
92
|
var SORTABLE_COLUMNS = [
|
|
81
93
|
"name",
|
|
@@ -116,8 +128,212 @@ var RESERVED_FIELDS = /* @__PURE__ */ new Set([
|
|
|
116
128
|
...CRM_SLOTS
|
|
117
129
|
]);
|
|
118
130
|
|
|
131
|
+
// src/schema.ts
|
|
132
|
+
var a = (type, o = {}) => ({
|
|
133
|
+
type,
|
|
134
|
+
unique: false,
|
|
135
|
+
indexed: false,
|
|
136
|
+
optional: false,
|
|
137
|
+
...o
|
|
138
|
+
});
|
|
139
|
+
var uniq = (type) => a(type, { unique: true, indexed: true });
|
|
140
|
+
var idx = (type, optional = false) => a(type, { indexed: true, optional });
|
|
141
|
+
var opt = (type) => a(type, { optional: true });
|
|
142
|
+
var CRM_SCHEMA = {
|
|
143
|
+
entities: {
|
|
144
|
+
[CRM_NS.record]: {
|
|
145
|
+
attrs: {
|
|
146
|
+
// Entity ids are not attributes in odla-db, so `where: { id }` matches
|
|
147
|
+
// nothing unless the id is mirrored as a written attr — the getRecord /
|
|
148
|
+
// tag-filter / neighbor reads all filter by id. Mirror it as unique.
|
|
149
|
+
id: uniq("string"),
|
|
150
|
+
type: idx("string"),
|
|
151
|
+
name: idx("string"),
|
|
152
|
+
primaryEmail: idx("string", true),
|
|
153
|
+
stage: idx("string", true),
|
|
154
|
+
stageIndex: idx("number", true),
|
|
155
|
+
stageChangedAt: idx("date", true),
|
|
156
|
+
rank: idx("number", true),
|
|
157
|
+
score: idx("number", true),
|
|
158
|
+
ownerId: idx("string", true),
|
|
159
|
+
emailStatus: idx("string", true),
|
|
160
|
+
clerkUserId: a("string", { unique: true, indexed: true, optional: true }),
|
|
161
|
+
stripeCustomerId: idx("string", true),
|
|
162
|
+
subscriptionId: opt("string"),
|
|
163
|
+
billingStatus: idx("string", true),
|
|
164
|
+
renewalAt: idx("date", true),
|
|
165
|
+
mrr: opt("number"),
|
|
166
|
+
s1: idx("string", true),
|
|
167
|
+
s2: idx("string", true),
|
|
168
|
+
s3: idx("string", true),
|
|
169
|
+
s4: idx("string", true),
|
|
170
|
+
n1: idx("number", true),
|
|
171
|
+
n2: idx("number", true),
|
|
172
|
+
n3: idx("number", true),
|
|
173
|
+
d1: idx("date", true),
|
|
174
|
+
d2: idx("date", true),
|
|
175
|
+
fields: a("json"),
|
|
176
|
+
searchText: a("string"),
|
|
177
|
+
archived: idx("boolean"),
|
|
178
|
+
createdAt: idx("date"),
|
|
179
|
+
updatedAt: idx("date"),
|
|
180
|
+
archivedAt: opt("date")
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
[CRM_NS.tag]: {
|
|
184
|
+
attrs: {
|
|
185
|
+
key: uniq("string"),
|
|
186
|
+
// `${recordId}:${tag}`
|
|
187
|
+
recordId: idx("string"),
|
|
188
|
+
tag: idx("string"),
|
|
189
|
+
createdAt: idx("date")
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
[CRM_NS.link]: {
|
|
193
|
+
attrs: {
|
|
194
|
+
key: uniq("string"),
|
|
195
|
+
// `${fromId}:${relation}:${toId}`
|
|
196
|
+
fromId: idx("string"),
|
|
197
|
+
toId: idx("string"),
|
|
198
|
+
relation: idx("string"),
|
|
199
|
+
createdAt: idx("date")
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
[CRM_NS.activity]: {
|
|
203
|
+
attrs: {
|
|
204
|
+
id: uniq("string"),
|
|
205
|
+
// mirrored so updateTask can read one by id
|
|
206
|
+
recordId: idx("string"),
|
|
207
|
+
kind: idx("string"),
|
|
208
|
+
body: a("string"),
|
|
209
|
+
status: idx("string", true),
|
|
210
|
+
// tasks: open | waiting | done
|
|
211
|
+
dueAt: idx("date", true),
|
|
212
|
+
waitingOn: opt("string"),
|
|
213
|
+
assigneeId: idx("string", true),
|
|
214
|
+
authorId: idx("string"),
|
|
215
|
+
createdAt: idx("date"),
|
|
216
|
+
completedAt: opt("date"),
|
|
217
|
+
meta: opt("json")
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
[CRM_NS.channel]: {
|
|
221
|
+
attrs: {
|
|
222
|
+
key: uniq("string"),
|
|
223
|
+
// `${recordId}:${kind}:${value}`
|
|
224
|
+
recordId: idx("string"),
|
|
225
|
+
kind: a("string"),
|
|
226
|
+
// email | phone
|
|
227
|
+
value: idx("string"),
|
|
228
|
+
// emails lowercased
|
|
229
|
+
isPrimary: a("boolean"),
|
|
230
|
+
consent: idx("string"),
|
|
231
|
+
consentAt: idx("date"),
|
|
232
|
+
consentSource: opt("string"),
|
|
233
|
+
unsubscribeToken: uniq("string"),
|
|
234
|
+
createdAt: idx("date")
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
[CRM_NS.emailLog]: {
|
|
238
|
+
attrs: {
|
|
239
|
+
recordId: idx("string", true),
|
|
240
|
+
channelId: opt("string"),
|
|
241
|
+
to: a("string"),
|
|
242
|
+
templateId: idx("string"),
|
|
243
|
+
subject: a("string"),
|
|
244
|
+
transport: a("string"),
|
|
245
|
+
// sent | log-only
|
|
246
|
+
redirected: opt("boolean"),
|
|
247
|
+
dedupeKey: idx("string", true),
|
|
248
|
+
messageId: opt("string"),
|
|
249
|
+
error: opt("string"),
|
|
250
|
+
sentAt: idx("date")
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
[CRM_NS.view]: {
|
|
254
|
+
attrs: {
|
|
255
|
+
id: uniq("string"),
|
|
256
|
+
// mirrored so getView/updateView can read one by id
|
|
257
|
+
name: a("string"),
|
|
258
|
+
type: idx("string"),
|
|
259
|
+
ownerId: idx("string", true),
|
|
260
|
+
shared: idx("boolean"),
|
|
261
|
+
filters: a("json"),
|
|
262
|
+
sort: a("json"),
|
|
263
|
+
columns: a("json"),
|
|
264
|
+
createdAt: idx("date"),
|
|
265
|
+
updatedAt: idx("date")
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
[CRM_NS.config]: {
|
|
269
|
+
attrs: {
|
|
270
|
+
key: uniq("string"),
|
|
271
|
+
// CONFIG_KEY singleton
|
|
272
|
+
notificationEmail: opt("string"),
|
|
273
|
+
replyTo: opt("string"),
|
|
274
|
+
debugEmail: opt("string"),
|
|
275
|
+
emailTemplates: a("json"),
|
|
276
|
+
// Record<templateId, {subject, text, enabled}>
|
|
277
|
+
settings: a("json"),
|
|
278
|
+
updatedAt: idx("date")
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
[CRM_NS.origin]: {
|
|
282
|
+
attrs: {
|
|
283
|
+
// One upstream record maps to one local record. The structured source
|
|
284
|
+
// survives tag edits and supports more than one upstream site.
|
|
285
|
+
key: uniq("string"),
|
|
286
|
+
// `${sourceId}:${sourceRecordId}`
|
|
287
|
+
recordId: idx("string"),
|
|
288
|
+
sourceId: idx("string"),
|
|
289
|
+
sourceRecordId: idx("string"),
|
|
290
|
+
sourceUrl: opt("string"),
|
|
291
|
+
payloadVersion: idx("number"),
|
|
292
|
+
firstReceivedAt: idx("date"),
|
|
293
|
+
lastReceivedAt: idx("date")
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
[CRM_NS.delivery]: {
|
|
297
|
+
attrs: {
|
|
298
|
+
// The latest delivery state for one local record → target edge.
|
|
299
|
+
key: uniq("string"),
|
|
300
|
+
// `${recordId}:${targetId}`
|
|
301
|
+
recordId: idx("string"),
|
|
302
|
+
targetId: idx("string"),
|
|
303
|
+
remoteRecordId: idx("string", true),
|
|
304
|
+
status: idx("string"),
|
|
305
|
+
attempts: idx("number"),
|
|
306
|
+
payloadVersion: idx("number"),
|
|
307
|
+
lastAttemptAt: idx("date"),
|
|
308
|
+
deliveredAt: idx("date", true),
|
|
309
|
+
error: opt("string")
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
links: {}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// src/time.ts
|
|
317
|
+
var DATE_FIELDS = new Map(
|
|
318
|
+
Object.entries(CRM_SCHEMA.entities).map(([ns, entity]) => [
|
|
319
|
+
ns,
|
|
320
|
+
new Set(
|
|
321
|
+
Object.entries(entity.attrs).filter(([, attr]) => attr.type === "date").map(([label]) => label)
|
|
322
|
+
)
|
|
323
|
+
])
|
|
324
|
+
);
|
|
325
|
+
function epochOf(value) {
|
|
326
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
327
|
+
if (typeof value !== "string") return void 0;
|
|
328
|
+
const parsed = Date.parse(value);
|
|
329
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
330
|
+
}
|
|
331
|
+
|
|
119
332
|
// src/ui/columns.tsx
|
|
120
|
-
var dateText = (value) =>
|
|
333
|
+
var dateText = (value) => {
|
|
334
|
+
const ms = epochOf(value);
|
|
335
|
+
return ms === void 0 ? "\u2014" : new Date(ms).toISOString().slice(0, 10);
|
|
336
|
+
};
|
|
121
337
|
var PROMOTED = {
|
|
122
338
|
name: { header: "Name", cell: (r) => r.name },
|
|
123
339
|
primaryEmail: { header: "Email", cell: (r) => r.primaryEmail ?? "\u2014" },
|
|
@@ -364,7 +580,10 @@ function ChannelsCard({ channels }) {
|
|
|
364
580
|
import { useState as useState2 } from "preact/hooks";
|
|
365
581
|
import { Button as Button2, Checkbox, Field, Input, Select, Textarea } from "@odla-ai/ui/components";
|
|
366
582
|
import { jsx as jsx4, jsxs as jsxs4 } from "preact/jsx-runtime";
|
|
367
|
-
var dateInput = (value) =>
|
|
583
|
+
var dateInput = (value) => {
|
|
584
|
+
const ms = epochOf(value);
|
|
585
|
+
return ms === void 0 ? "" : new Date(ms).toISOString().slice(0, 10);
|
|
586
|
+
};
|
|
368
587
|
function initialDraft(def, record) {
|
|
369
588
|
const draft = {};
|
|
370
589
|
for (const [name, field] of Object.entries(def)) {
|