@ordinatio/entities 1.0.3 → 1.0.4

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.mjs CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  evaluateConstraint,
10
10
  fireObservers,
11
11
  knowledgeError
12
- } from "./chunk-QXBSEBJW.mjs";
12
+ } from "./chunk-WWGAALKG.mjs";
13
13
 
14
14
  // src/knowledge/field-definitions.ts
15
15
  import { Prisma } from "@prisma/client";
@@ -199,7 +199,7 @@ async function setEntityFields(db, entityType, entityId, fields, source, sourceI
199
199
  } catch {
200
200
  }
201
201
  try {
202
- const { fireObservers: fireObservers2 } = await import("./observer-YUTEGG4S.mjs");
202
+ const { fireObservers: fireObservers2 } = await import("./observer-2GIY55TX.mjs");
203
203
  await fireObservers2(db, entityType, entityId, results.map((r) => r.key), callbacks);
204
204
  } catch {
205
205
  }
@@ -1668,6 +1668,7 @@ async function createNote(db, input, callbacks) {
1668
1668
  isDraft: input.isDraft ?? false,
1669
1669
  authorId: input.authorId ?? null,
1670
1670
  source: input.source ?? "MANUAL",
1671
+ ...input.metadata ? { metadata: input.metadata } : {},
1671
1672
  ...input.attachments && input.attachments.length > 0 ? {
1672
1673
  attachments: {
1673
1674
  create: input.attachments.map((a) => ({
@@ -1726,6 +1727,21 @@ async function updateNote(db, noteId, entityId, input, callbacks) {
1726
1727
  });
1727
1728
  if (!note) return null;
1728
1729
  const isPublishing = note.isDraft && input.isDraft === false;
1730
+ const isContentChange = input.content !== void 0 && input.content !== note.content || input.contentHtml !== void 0 && input.contentHtml !== note.contentHtml;
1731
+ if (isContentChange && !note.isDraft) {
1732
+ try {
1733
+ await db.clientNoteRevision.create({
1734
+ data: {
1735
+ noteId: note.id,
1736
+ content: note.content,
1737
+ contentHtml: note.contentHtml,
1738
+ editedBy: input.editedBy ?? note.authorId,
1739
+ editedAt: /* @__PURE__ */ new Date()
1740
+ }
1741
+ });
1742
+ } catch {
1743
+ }
1744
+ }
1729
1745
  const updated = await db.clientNote.update({
1730
1746
  where: { id: noteId },
1731
1747
  data: {
@@ -1735,7 +1751,11 @@ async function updateNote(db, noteId, entityId, input, callbacks) {
1735
1751
  },
1736
1752
  include: {
1737
1753
  author: { select: { id: true, name: true } },
1738
- attachments: true
1754
+ attachments: true,
1755
+ revisions: {
1756
+ orderBy: { editedAt: "desc" },
1757
+ select: { id: true, content: true, editedBy: true, editedAt: true }
1758
+ }
1739
1759
  }
1740
1760
  });
1741
1761
  if (input.attachments !== void 0) {
@@ -1752,6 +1772,26 @@ async function updateNote(db, noteId, entityId, input, callbacks) {
1752
1772
  });
1753
1773
  }
1754
1774
  }
1775
+ if (isContentChange && !note.isDraft && !isPublishing) {
1776
+ try {
1777
+ const noteContent = input.content ?? note.content;
1778
+ const truncated = truncateText(noteContent, 200);
1779
+ await callbacks?.logActivity?.(
1780
+ "CLIENT_NOTE_EDITED",
1781
+ `Note edited: ${truncated}`,
1782
+ {
1783
+ userId: input.editedBy ?? note.authorId ?? null,
1784
+ clientId: entityId,
1785
+ metadata: {
1786
+ noteId,
1787
+ contentPreview: truncateText(noteContent, 500),
1788
+ revisionCount: updated.revisions?.length ?? 0
1789
+ }
1790
+ }
1791
+ );
1792
+ } catch {
1793
+ }
1794
+ }
1755
1795
  if (isPublishing) {
1756
1796
  try {
1757
1797
  const noteContent = input.content ?? note.content;
@@ -1776,7 +1816,11 @@ async function updateNote(db, noteId, entityId, input, callbacks) {
1776
1816
  where: { id: noteId },
1777
1817
  include: {
1778
1818
  author: { select: { id: true, name: true } },
1779
- attachments: true
1819
+ attachments: true,
1820
+ revisions: {
1821
+ orderBy: { editedAt: "desc" },
1822
+ select: { id: true, content: true, editedBy: true, editedAt: true }
1823
+ }
1780
1824
  }
1781
1825
  });
1782
1826
  }
@@ -1960,6 +2004,7 @@ async function findOrCreateContact(db, email, name, source = "EMAIL_SYNC") {
1960
2004
  }
1961
2005
 
1962
2006
  // src/knowledge/contact-fields-seed.ts
2007
+ import { Prisma as Prisma4 } from "@prisma/client";
1963
2008
  var CONTACT_FIELD_DEFINITIONS = [
1964
2009
  // --- Communication ---
1965
2010
  { entityType: "contact", key: "preferred_contact_method", label: "Preferred Contact Method", dataType: "enum", category: "communication", enumOptions: ["email", "phone", "text", "in-person"], sortOrder: 0 },
@@ -1982,7 +2027,7 @@ async function seedContactFieldDefinitions(db) {
1982
2027
  label: d.label,
1983
2028
  dataType: d.dataType,
1984
2029
  category: d.category,
1985
- enumOptions: "enumOptions" in d ? d.enumOptions : null,
2030
+ enumOptions: "enumOptions" in d ? [...d.enumOptions] : Prisma4.JsonNull,
1986
2031
  extractionHint: "extractionHint" in d ? d.extractionHint : null,
1987
2032
  sortOrder: d.sortOrder,
1988
2033
  status: "approved",
@@ -2119,7 +2164,7 @@ var CreateNoteSchema = z3.object({
2119
2164
  content: z3.string().min(1, "Note content is required").max(5e3, "Note content must be 5000 characters or fewer"),
2120
2165
  contentHtml: z3.string().max(5e4).optional(),
2121
2166
  isDraft: z3.boolean().default(false),
2122
- source: z3.enum(["MANUAL", "AGENT", "SYSTEM"]).default("MANUAL"),
2167
+ source: z3.enum(["MANUAL", "AGENT", "SYSTEM", "QUOTE"]).default("MANUAL"),
2123
2168
  attachments: z3.array(AttachmentSchema).max(5, "Maximum 5 attachments").default([]),
2124
2169
  fields: z3.record(z3.string(), z3.unknown()).optional()
2125
2170
  });
@@ -2,7 +2,7 @@ import {
2
2
  checkConstraints,
3
3
  evaluateConstraint,
4
4
  fireObservers
5
- } from "./chunk-QXBSEBJW.mjs";
5
+ } from "./chunk-WWGAALKG.mjs";
6
6
  export {
7
7
  checkConstraints,
8
8
  evaluateConstraint,
package/package.json CHANGED
@@ -1,44 +1,31 @@
1
1
  {
2
2
  "name": "@ordinatio/entities",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Entity knowledge, agent intelligence, notes, and contacts",
7
7
  "engines": {
8
8
  "node": ">=22.0.0"
9
9
  },
10
- "main": "./src/index.ts",
11
- "types": "./src/index.ts",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
12
  "exports": {
13
13
  ".": {
14
- "import": "./src/index.ts",
15
- "types": "./src/index.ts"
16
- },
17
- "./schemas": "./src/schemas.ts",
18
- "./errors": "./src/errors.ts"
14
+ "import": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
19
17
  },
20
18
  "publishConfig": {
21
- "access": "public",
22
- "main": "./dist/index.js",
23
- "types": "./dist/index.d.ts",
24
- "exports": {
25
- ".": {
26
- "import": "./dist/index.js",
27
- "types": "./dist/index.d.ts"
28
- }
29
- }
19
+ "access": "public"
30
20
  },
31
21
  "files": [
32
22
  "dist",
33
23
  "README.md",
34
24
  "LICENSE"
35
25
  ],
36
- "scripts": {
37
- "build": "tsup src/index.ts --format esm --clean",
38
- "test": "vitest",
39
- "test:run": "vitest run"
26
+ "dependencies": {
27
+ "@ordinatio/errors": "1.0.0"
40
28
  },
41
- "dependencies": {},
42
29
  "devDependencies": {
43
30
  "@ordinatio/core": "^1.0.0",
44
31
  "fast-check": "^4.5.3",
@@ -54,5 +41,10 @@
54
41
  "@prisma/client": {
55
42
  "optional": true
56
43
  }
44
+ },
45
+ "scripts": {
46
+ "build": "tsup src/index.ts --format esm --dts --clean",
47
+ "test": "vitest",
48
+ "test:run": "vitest run"
57
49
  }
58
50
  }