@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.cjs
CHANGED
|
@@ -6117,7 +6117,7 @@ var handleAdminNetworkPush = async (req, url, env, ctx) => {
|
|
|
6117
6117
|
};
|
|
6118
6118
|
|
|
6119
6119
|
// src/worker-routes-network-records-follower.ts
|
|
6120
|
-
var
|
|
6120
|
+
var import_crm10 = require("@odla-ai/crm");
|
|
6121
6121
|
var import_db9 = require("@odla-ai/db");
|
|
6122
6122
|
|
|
6123
6123
|
// src/worker-routes-network-records-common.ts
|
|
@@ -6212,6 +6212,45 @@ function restrictedRecord(record4, target) {
|
|
|
6212
6212
|
return { ...record4, ...edit ? { edit } : { edit: void 0 } };
|
|
6213
6213
|
}
|
|
6214
6214
|
|
|
6215
|
+
// src/worker-routes-network-records-search.ts
|
|
6216
|
+
var import_crm9 = require("@odla-ai/crm");
|
|
6217
|
+
var MAX_SAFE_LIKE_BYTES = 50;
|
|
6218
|
+
function safePrefix(value) {
|
|
6219
|
+
const prefixed = `${value}%`;
|
|
6220
|
+
return value.includes("%") || value.includes("_") || new TextEncoder().encode(prefixed).byteLength > MAX_SAFE_LIKE_BYTES ? value : { $like: prefixed };
|
|
6221
|
+
}
|
|
6222
|
+
async function listReaderRecords(db, type, allowed2, emailField, window) {
|
|
6223
|
+
const clauses = [
|
|
6224
|
+
{ type },
|
|
6225
|
+
{ archived: false },
|
|
6226
|
+
...window.stage ? [{ stage: window.stage }] : []
|
|
6227
|
+
];
|
|
6228
|
+
if (window.search) {
|
|
6229
|
+
const visible = [{ name: safePrefix(window.search) }];
|
|
6230
|
+
if (emailField && allowed2.includes(emailField)) {
|
|
6231
|
+
visible.push({ primaryEmail: safePrefix(window.search.toLowerCase()) });
|
|
6232
|
+
}
|
|
6233
|
+
clauses.push({ or: visible });
|
|
6234
|
+
}
|
|
6235
|
+
const where = { and: clauses };
|
|
6236
|
+
const crmDb = db;
|
|
6237
|
+
const [result, aggregate] = await Promise.all([
|
|
6238
|
+
crmDb.query({
|
|
6239
|
+
[import_crm9.CRM_NS.record]: { $: {
|
|
6240
|
+
where,
|
|
6241
|
+
order: { [window.sort.field]: window.sort.dir },
|
|
6242
|
+
limit: window.limit,
|
|
6243
|
+
offset: window.offset
|
|
6244
|
+
} }
|
|
6245
|
+
}),
|
|
6246
|
+
crmDb.aggregate(import_crm9.CRM_NS.record, { count: true }, { where })
|
|
6247
|
+
]);
|
|
6248
|
+
return {
|
|
6249
|
+
records: (result[import_crm9.CRM_NS.record] ?? []).map(import_crm9.rowToRecord),
|
|
6250
|
+
total: aggregate.count ?? 0
|
|
6251
|
+
};
|
|
6252
|
+
}
|
|
6253
|
+
|
|
6215
6254
|
// src/worker-routes-network-records-follower.ts
|
|
6216
6255
|
var NETWORK_MUTATION_META = "chapterNetworkMutation";
|
|
6217
6256
|
function mutationFingerprint(input) {
|
|
@@ -6231,16 +6270,16 @@ function mutationError(error) {
|
|
|
6231
6270
|
if (error?.code === "transact_guard_failed") {
|
|
6232
6271
|
return json({ error: "record changed since it was reviewed", code: "stale_revision" }, 409);
|
|
6233
6272
|
}
|
|
6234
|
-
if (error instanceof
|
|
6273
|
+
if (error instanceof import_crm10.CrmInputError) {
|
|
6235
6274
|
return json({ error: error.message, code: "invalid_transition_or_fields", ...error.fields ? { fields: error.fields } : {} }, 422);
|
|
6236
6275
|
}
|
|
6237
6276
|
return json({ error: "follower mutation failed", code: "mutation_failed" }, 500);
|
|
6238
6277
|
}
|
|
6239
6278
|
async function priorMutation(db, id) {
|
|
6240
6279
|
const result = await db.query({
|
|
6241
|
-
[
|
|
6280
|
+
[import_crm10.CRM_NS.activity]: { $: { where: { id }, limit: 1 } }
|
|
6242
6281
|
});
|
|
6243
|
-
const row = (result[
|
|
6282
|
+
const row = (result[import_crm10.CRM_NS.activity] ?? [])[0];
|
|
6244
6283
|
const meta = row?.meta;
|
|
6245
6284
|
const receipt = meta?.[NETWORK_MUTATION_META];
|
|
6246
6285
|
return typeof receipt?.fingerprint === "string" ? { fingerprint: receipt.fingerprint } : null;
|
|
@@ -6294,7 +6333,7 @@ var handleNetworkRecords = async (req, url, env, ctx) => {
|
|
|
6294
6333
|
if (prior.fingerprint !== fingerprint) {
|
|
6295
6334
|
return json({ error: "mutationId was already used for different input", code: "mutation_conflict" }, 409);
|
|
6296
6335
|
}
|
|
6297
|
-
const replayed = await (0,
|
|
6336
|
+
const replayed = await (0, import_crm10.getRecord)({ crm: ctx.chapter.crm, db }, input.recordId);
|
|
6298
6337
|
if (!replayed || replayed.type !== input.type) return json({ error: "record not found", code: "not_found" }, 404);
|
|
6299
6338
|
const result = {
|
|
6300
6339
|
version: 1,
|
|
@@ -6304,7 +6343,7 @@ var handleNetworkRecords = async (req, url, env, ctx) => {
|
|
|
6304
6343
|
};
|
|
6305
6344
|
return json(result);
|
|
6306
6345
|
}
|
|
6307
|
-
const record4 = await (0,
|
|
6346
|
+
const record4 = await (0, import_crm10.getRecord)({ crm: ctx.chapter.crm, db }, input.recordId);
|
|
6308
6347
|
if (!record4 || record4.type !== input.type) return json({ error: "record not found", code: "not_found" }, 404);
|
|
6309
6348
|
if (record4.updatedAt !== input.expectedRevision) {
|
|
6310
6349
|
return json({ error: "record changed since it was reviewed", code: "stale_revision" }, 409);
|
|
@@ -6325,7 +6364,7 @@ var handleNetworkRecords = async (req, url, env, ctx) => {
|
|
|
6325
6364
|
};
|
|
6326
6365
|
try {
|
|
6327
6366
|
const deps2 = { crm: ctx.chapter.crm, db };
|
|
6328
|
-
const updated = hasFields ? await (0,
|
|
6367
|
+
const updated = hasFields ? await (0, import_crm10.updateRecord)(deps2, {
|
|
6329
6368
|
id: record4.id,
|
|
6330
6369
|
input: fields,
|
|
6331
6370
|
mutationId: activityId,
|
|
@@ -6336,7 +6375,7 @@ var handleNetworkRecords = async (req, url, env, ctx) => {
|
|
|
6336
6375
|
authorId: `network:${verified.sender}`,
|
|
6337
6376
|
meta: auditMeta
|
|
6338
6377
|
}
|
|
6339
|
-
}) : await (0,
|
|
6378
|
+
}) : await (0, import_crm10.setStage)(deps2, {
|
|
6340
6379
|
id: record4.id,
|
|
6341
6380
|
to: input.stage,
|
|
6342
6381
|
authorId: `network:${verified.sender}`,
|
|
@@ -6367,16 +6406,12 @@ var handleNetworkRecords = async (req, url, env, ctx) => {
|
|
|
6367
6406
|
if (window.stage && !stages.some((stage) => stage.id === window.stage)) {
|
|
6368
6407
|
return json({ error: "stage is not defined for this record type" }, 400);
|
|
6369
6408
|
}
|
|
6370
|
-
const page = await (
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
...window.search ? { search: window.search } : {},
|
|
6377
|
-
...window.stage ? { stage: [window.stage] } : {},
|
|
6378
|
-
sort: window.sort
|
|
6379
|
-
}
|
|
6409
|
+
const page = await listReaderRecords(
|
|
6410
|
+
db,
|
|
6411
|
+
type,
|
|
6412
|
+
allowed2,
|
|
6413
|
+
typeDef.emailField,
|
|
6414
|
+
window
|
|
6380
6415
|
);
|
|
6381
6416
|
const response = {
|
|
6382
6417
|
version: 1,
|
|
@@ -6384,8 +6419,8 @@ var handleNetworkRecords = async (req, url, env, ctx) => {
|
|
|
6384
6419
|
type,
|
|
6385
6420
|
records: page.records.map((record4) => readerRecord(record4, reader, ctx.chapter.crm)),
|
|
6386
6421
|
total: page.total,
|
|
6387
|
-
limit:
|
|
6388
|
-
offset:
|
|
6422
|
+
limit: window.limit,
|
|
6423
|
+
offset: window.offset,
|
|
6389
6424
|
filters: {
|
|
6390
6425
|
stages: stages.map((stage) => ({ id: stage.id, label: stage.label ?? stage.id })),
|
|
6391
6426
|
sorts: [...NETWORK_RECORD_SORTS]
|
|
@@ -6621,7 +6656,7 @@ var handleAdminNetworkNotes = async (req, url, env, ctx) => {
|
|
|
6621
6656
|
};
|
|
6622
6657
|
|
|
6623
6658
|
// src/worker-routes-network-shared-notes.ts
|
|
6624
|
-
var
|
|
6659
|
+
var import_crm11 = require("@odla-ai/crm");
|
|
6625
6660
|
var import_db11 = require("@odla-ai/db");
|
|
6626
6661
|
var IDENTIFIER3 = /^[a-z][a-zA-Z0-9_]*$/;
|
|
6627
6662
|
var RECORD_ID3 = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/;
|
|
@@ -6651,7 +6686,7 @@ function sharedNote(activity, sourceId) {
|
|
|
6651
6686
|
}
|
|
6652
6687
|
async function listSharedNotes(db, sourceId, recordId) {
|
|
6653
6688
|
const result = await db.query({
|
|
6654
|
-
[
|
|
6689
|
+
[import_crm11.CRM_NS.activity]: {
|
|
6655
6690
|
$: {
|
|
6656
6691
|
where: {
|
|
6657
6692
|
and: [
|
|
@@ -6664,7 +6699,7 @@ async function listSharedNotes(db, sourceId, recordId) {
|
|
|
6664
6699
|
}
|
|
6665
6700
|
}
|
|
6666
6701
|
});
|
|
6667
|
-
return (result[
|
|
6702
|
+
return (result[import_crm11.CRM_NS.activity] ?? []).flatMap((activity) => {
|
|
6668
6703
|
const note = sharedNote(activity, sourceId);
|
|
6669
6704
|
return note ? [note] : [];
|
|
6670
6705
|
});
|
|
@@ -6692,7 +6727,7 @@ var handleNetworkSharedNotes = async (req, url, env, ctx) => {
|
|
|
6692
6727
|
if (!IDENTIFIER3.test(recordType) || !RECORD_ID3.test(recordId) || !reader?.sharedNotes.includes(recordType)) {
|
|
6693
6728
|
return json({ error: "shared notes are not enabled for this reader and record type" }, 403);
|
|
6694
6729
|
}
|
|
6695
|
-
const record4 = await (0,
|
|
6730
|
+
const record4 = await (0, import_crm11.getRecord)({ crm: ctx.chapter.crm, db }, recordId);
|
|
6696
6731
|
if (!record4 || record4.type !== recordType) return json({ error: "record not found" }, 404);
|
|
6697
6732
|
if (req.method === "GET") {
|
|
6698
6733
|
return json({
|
|
@@ -6714,7 +6749,7 @@ var handleNetworkSharedNotes = async (req, url, env, ctx) => {
|
|
|
6714
6749
|
}
|
|
6715
6750
|
const createdAt = Date.now();
|
|
6716
6751
|
const id = `network:${verified.sender}:${mutationId}`;
|
|
6717
|
-
const result = await (0,
|
|
6752
|
+
const result = await (0, import_crm11.addActivity)(
|
|
6718
6753
|
{
|
|
6719
6754
|
crm: ctx.chapter.crm,
|
|
6720
6755
|
db,
|
|
@@ -8287,7 +8322,7 @@ var handleAdminNetworkCommercialReadModel = async (req, url, env, ctx) => {
|
|
|
8287
8322
|
};
|
|
8288
8323
|
|
|
8289
8324
|
// src/worker-routes-formation.ts
|
|
8290
|
-
var
|
|
8325
|
+
var import_crm12 = require("@odla-ai/crm");
|
|
8291
8326
|
var SUBMISSION = /^[A-Za-z0-9_-]{8,128}$/;
|
|
8292
8327
|
var handleFormation = async (req, url, env, ctx) => {
|
|
8293
8328
|
const formation = ctx.chapter.formation;
|
|
@@ -8339,7 +8374,7 @@ var handleFormation = async (req, url, env, ctx) => {
|
|
|
8339
8374
|
const db = ctx.makeDb(env);
|
|
8340
8375
|
const id = submissionId ? await applicationIdForSubmission(`formation:${ctx.chapter.id}:${submissionId}`) : crypto.randomUUID();
|
|
8341
8376
|
try {
|
|
8342
|
-
const created = await (0,
|
|
8377
|
+
const created = await (0, import_crm12.createRecord)(
|
|
8343
8378
|
{
|
|
8344
8379
|
crm: ctx.chapter.crm,
|
|
8345
8380
|
db,
|