@odla-ai/crm 0.7.1 → 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 +45 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -20
- package/dist/index.js.map +1 -1
- package/dist/ui/index.js +205 -0
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -766,11 +766,53 @@ function crmDiscussionReferenceHref(current, target, basePath = "/admin/") {
|
|
|
766
766
|
return next.toString();
|
|
767
767
|
}
|
|
768
768
|
|
|
769
|
+
// src/time.ts
|
|
770
|
+
var DATE_FIELDS = new Map(
|
|
771
|
+
Object.entries(CRM_SCHEMA.entities).map(([ns, entity]) => [
|
|
772
|
+
ns,
|
|
773
|
+
new Set(
|
|
774
|
+
Object.entries(entity.attrs).filter(([, attr]) => attr.type === "date").map(([label]) => label)
|
|
775
|
+
)
|
|
776
|
+
])
|
|
777
|
+
);
|
|
778
|
+
function epochOf(value) {
|
|
779
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
780
|
+
if (typeof value !== "string") return void 0;
|
|
781
|
+
const parsed = Date.parse(value);
|
|
782
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
783
|
+
}
|
|
784
|
+
function rowAsWritten(ns, row) {
|
|
785
|
+
const dates = DATE_FIELDS.get(ns);
|
|
786
|
+
if (!dates?.size) return row;
|
|
787
|
+
const out = { ...row };
|
|
788
|
+
for (const field of dates) {
|
|
789
|
+
if (!(field in out)) continue;
|
|
790
|
+
const parsed = epochOf(out[field]);
|
|
791
|
+
if (parsed === void 0) delete out[field];
|
|
792
|
+
else out[field] = parsed;
|
|
793
|
+
}
|
|
794
|
+
return out;
|
|
795
|
+
}
|
|
796
|
+
function resultAsWritten(result) {
|
|
797
|
+
const out = { ...result };
|
|
798
|
+
for (const [ns, rows] of Object.entries(out)) {
|
|
799
|
+
if (Array.isArray(rows)) out[ns] = rows.map((row) => rowAsWritten(ns, row));
|
|
800
|
+
}
|
|
801
|
+
return out;
|
|
802
|
+
}
|
|
803
|
+
|
|
769
804
|
// src/deps.ts
|
|
805
|
+
function readingAsWritten(db) {
|
|
806
|
+
return {
|
|
807
|
+
query: async (query) => resultAsWritten(await db.query(query)),
|
|
808
|
+
transact: (ops, opts) => db.transact(ops, opts),
|
|
809
|
+
aggregate: (ns, spec, queryOpts) => db.aggregate(ns, spec, queryOpts)
|
|
810
|
+
};
|
|
811
|
+
}
|
|
770
812
|
function resolveDeps(deps) {
|
|
771
813
|
return {
|
|
772
814
|
crm: deps.crm,
|
|
773
|
-
db: deps.db,
|
|
815
|
+
db: readingAsWritten(deps.db),
|
|
774
816
|
now: deps.now ?? Date.now,
|
|
775
817
|
newId: deps.newId ?? (() => crypto.randomUUID())
|
|
776
818
|
};
|
|
@@ -1308,14 +1350,6 @@ async function listLinks(deps, recordId) {
|
|
|
1308
1350
|
return (result[CRM_NS.link] ?? []).map((row) => row);
|
|
1309
1351
|
}
|
|
1310
1352
|
|
|
1311
|
-
// src/time.ts
|
|
1312
|
-
function epochOf(value) {
|
|
1313
|
-
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
1314
|
-
if (typeof value !== "string") return void 0;
|
|
1315
|
-
const parsed = Date.parse(value);
|
|
1316
|
-
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
1353
|
// src/provenance.ts
|
|
1320
1354
|
var SOURCE_ID = /^[a-z0-9][a-z0-9-]{1,127}$/;
|
|
1321
1355
|
var TARGET_ID = SOURCE_ID;
|
|
@@ -1330,20 +1364,11 @@ function recordOriginKey(sourceId, sourceRecordId) {
|
|
|
1330
1364
|
if (!SOURCE_ID.test(source)) throw new CrmInputError("sourceId must be a lowercase app slug");
|
|
1331
1365
|
return `${source}:${record}`;
|
|
1332
1366
|
}
|
|
1333
|
-
function originRow(row) {
|
|
1334
|
-
const out = { ...row };
|
|
1335
|
-
for (const field of ["firstReceivedAt", "lastReceivedAt"]) {
|
|
1336
|
-
const parsed = epochOf(out[field]);
|
|
1337
|
-
if (parsed !== void 0) out[field] = parsed;
|
|
1338
|
-
}
|
|
1339
|
-
return out;
|
|
1340
|
-
}
|
|
1341
1367
|
async function getRecordOrigin(deps, sourceId, sourceRecordId) {
|
|
1342
1368
|
const { db } = resolveDeps(deps);
|
|
1343
1369
|
const key = recordOriginKey(sourceId, sourceRecordId);
|
|
1344
1370
|
const result = await db.query({ [CRM_NS.origin]: { $: { where: { key }, limit: 1 } } });
|
|
1345
|
-
|
|
1346
|
-
return row ? originRow(row) : null;
|
|
1371
|
+
return (result[CRM_NS.origin] ?? [])[0] ?? null;
|
|
1347
1372
|
}
|
|
1348
1373
|
async function getRecordByOrigin(deps, sourceId, sourceRecordId) {
|
|
1349
1374
|
const origin = await getRecordOrigin(deps, sourceId, sourceRecordId);
|
|
@@ -1389,7 +1414,7 @@ async function listRecordOrigins(deps, recordId) {
|
|
|
1389
1414
|
const result = await db.query({
|
|
1390
1415
|
[CRM_NS.origin]: { $: { where: { recordId }, order: { firstReceivedAt: "asc" }, limit: 200 } }
|
|
1391
1416
|
});
|
|
1392
|
-
return
|
|
1417
|
+
return result[CRM_NS.origin] ?? [];
|
|
1393
1418
|
}
|
|
1394
1419
|
function recordDeliveryKey(recordId, targetId) {
|
|
1395
1420
|
const record = required(recordId, "recordId");
|