@odla-ai/chapter 0.47.1 → 0.47.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/worker/index.cjs +62 -27
- package/dist/worker/index.cjs.map +1 -1
- package/dist/worker/index.js +59 -18
- package/dist/worker/index.js.map +1 -1
- package/package.json +1 -1
package/dist/worker/index.js
CHANGED
|
@@ -6087,7 +6087,13 @@ var handleAdminNetworkPush = async (req, url, env, ctx) => {
|
|
|
6087
6087
|
};
|
|
6088
6088
|
|
|
6089
6089
|
// src/worker-routes-network-records-follower.ts
|
|
6090
|
-
import {
|
|
6090
|
+
import {
|
|
6091
|
+
CRM_NS as CRM_NS2,
|
|
6092
|
+
CrmInputError,
|
|
6093
|
+
getRecord as getRecord4,
|
|
6094
|
+
setStage as setStage2,
|
|
6095
|
+
updateRecord as updateRecord3
|
|
6096
|
+
} from "@odla-ai/crm";
|
|
6091
6097
|
import { verifyFederatedRequest as verifyFederatedRequest6 } from "@odla-ai/db";
|
|
6092
6098
|
|
|
6093
6099
|
// src/worker-routes-network-records-common.ts
|
|
@@ -6182,6 +6188,45 @@ function restrictedRecord(record4, target) {
|
|
|
6182
6188
|
return { ...record4, ...edit ? { edit } : { edit: void 0 } };
|
|
6183
6189
|
}
|
|
6184
6190
|
|
|
6191
|
+
// src/worker-routes-network-records-search.ts
|
|
6192
|
+
import { CRM_NS, rowToRecord } from "@odla-ai/crm";
|
|
6193
|
+
var MAX_SAFE_LIKE_BYTES = 50;
|
|
6194
|
+
function safePrefix(value) {
|
|
6195
|
+
const prefixed = `${value}%`;
|
|
6196
|
+
return value.includes("%") || value.includes("_") || new TextEncoder().encode(prefixed).byteLength > MAX_SAFE_LIKE_BYTES ? value : { $like: prefixed };
|
|
6197
|
+
}
|
|
6198
|
+
async function listReaderRecords(db, type, allowed2, emailField, window) {
|
|
6199
|
+
const clauses = [
|
|
6200
|
+
{ type },
|
|
6201
|
+
{ archived: false },
|
|
6202
|
+
...window.stage ? [{ stage: window.stage }] : []
|
|
6203
|
+
];
|
|
6204
|
+
if (window.search) {
|
|
6205
|
+
const visible = [{ name: safePrefix(window.search) }];
|
|
6206
|
+
if (emailField && allowed2.includes(emailField)) {
|
|
6207
|
+
visible.push({ primaryEmail: safePrefix(window.search.toLowerCase()) });
|
|
6208
|
+
}
|
|
6209
|
+
clauses.push({ or: visible });
|
|
6210
|
+
}
|
|
6211
|
+
const where = { and: clauses };
|
|
6212
|
+
const crmDb = db;
|
|
6213
|
+
const [result, aggregate] = await Promise.all([
|
|
6214
|
+
crmDb.query({
|
|
6215
|
+
[CRM_NS.record]: { $: {
|
|
6216
|
+
where,
|
|
6217
|
+
order: { [window.sort.field]: window.sort.dir },
|
|
6218
|
+
limit: window.limit,
|
|
6219
|
+
offset: window.offset
|
|
6220
|
+
} }
|
|
6221
|
+
}),
|
|
6222
|
+
crmDb.aggregate(CRM_NS.record, { count: true }, { where })
|
|
6223
|
+
]);
|
|
6224
|
+
return {
|
|
6225
|
+
records: (result[CRM_NS.record] ?? []).map(rowToRecord),
|
|
6226
|
+
total: aggregate.count ?? 0
|
|
6227
|
+
};
|
|
6228
|
+
}
|
|
6229
|
+
|
|
6185
6230
|
// src/worker-routes-network-records-follower.ts
|
|
6186
6231
|
var NETWORK_MUTATION_META = "chapterNetworkMutation";
|
|
6187
6232
|
function mutationFingerprint(input) {
|
|
@@ -6208,9 +6253,9 @@ function mutationError(error) {
|
|
|
6208
6253
|
}
|
|
6209
6254
|
async function priorMutation(db, id) {
|
|
6210
6255
|
const result = await db.query({
|
|
6211
|
-
[
|
|
6256
|
+
[CRM_NS2.activity]: { $: { where: { id }, limit: 1 } }
|
|
6212
6257
|
});
|
|
6213
|
-
const row = (result[
|
|
6258
|
+
const row = (result[CRM_NS2.activity] ?? [])[0];
|
|
6214
6259
|
const meta = row?.meta;
|
|
6215
6260
|
const receipt = meta?.[NETWORK_MUTATION_META];
|
|
6216
6261
|
return typeof receipt?.fingerprint === "string" ? { fingerprint: receipt.fingerprint } : null;
|
|
@@ -6337,16 +6382,12 @@ var handleNetworkRecords = async (req, url, env, ctx) => {
|
|
|
6337
6382
|
if (window.stage && !stages.some((stage) => stage.id === window.stage)) {
|
|
6338
6383
|
return json({ error: "stage is not defined for this record type" }, 400);
|
|
6339
6384
|
}
|
|
6340
|
-
const page = await
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
...window.search ? { search: window.search } : {},
|
|
6347
|
-
...window.stage ? { stage: [window.stage] } : {},
|
|
6348
|
-
sort: window.sort
|
|
6349
|
-
}
|
|
6385
|
+
const page = await listReaderRecords(
|
|
6386
|
+
db,
|
|
6387
|
+
type,
|
|
6388
|
+
allowed2,
|
|
6389
|
+
typeDef.emailField,
|
|
6390
|
+
window
|
|
6350
6391
|
);
|
|
6351
6392
|
const response = {
|
|
6352
6393
|
version: 1,
|
|
@@ -6354,8 +6395,8 @@ var handleNetworkRecords = async (req, url, env, ctx) => {
|
|
|
6354
6395
|
type,
|
|
6355
6396
|
records: page.records.map((record4) => readerRecord(record4, reader, ctx.chapter.crm)),
|
|
6356
6397
|
total: page.total,
|
|
6357
|
-
limit:
|
|
6358
|
-
offset:
|
|
6398
|
+
limit: window.limit,
|
|
6399
|
+
offset: window.offset,
|
|
6359
6400
|
filters: {
|
|
6360
6401
|
stages: stages.map((stage) => ({ id: stage.id, label: stage.label ?? stage.id })),
|
|
6361
6402
|
sorts: [...NETWORK_RECORD_SORTS]
|
|
@@ -6593,7 +6634,7 @@ var handleAdminNetworkNotes = async (req, url, env, ctx) => {
|
|
|
6593
6634
|
// src/worker-routes-network-shared-notes.ts
|
|
6594
6635
|
import {
|
|
6595
6636
|
addActivity,
|
|
6596
|
-
CRM_NS as
|
|
6637
|
+
CRM_NS as CRM_NS3,
|
|
6597
6638
|
getRecord as getRecord5
|
|
6598
6639
|
} from "@odla-ai/crm";
|
|
6599
6640
|
import { signFederatedRequest as signFederatedRequest5, verifyFederatedRequest as verifyFederatedRequest7 } from "@odla-ai/db";
|
|
@@ -6625,7 +6666,7 @@ function sharedNote(activity, sourceId) {
|
|
|
6625
6666
|
}
|
|
6626
6667
|
async function listSharedNotes(db, sourceId, recordId) {
|
|
6627
6668
|
const result = await db.query({
|
|
6628
|
-
[
|
|
6669
|
+
[CRM_NS3.activity]: {
|
|
6629
6670
|
$: {
|
|
6630
6671
|
where: {
|
|
6631
6672
|
and: [
|
|
@@ -6638,7 +6679,7 @@ async function listSharedNotes(db, sourceId, recordId) {
|
|
|
6638
6679
|
}
|
|
6639
6680
|
}
|
|
6640
6681
|
});
|
|
6641
|
-
return (result[
|
|
6682
|
+
return (result[CRM_NS3.activity] ?? []).flatMap((activity) => {
|
|
6642
6683
|
const note = sharedNote(activity, sourceId);
|
|
6643
6684
|
return note ? [note] : [];
|
|
6644
6685
|
});
|