@opencxh/domain 1.29.0 → 1.31.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.
@@ -1 +1,2 @@
1
1
  export * from './types';
2
+ export * from './preview';
@@ -0,0 +1,3 @@
1
+ import { ActivityPreview } from '../interaction/types';
2
+ import { Activity } from './types';
3
+ export declare function buildActivityPreview(activity: Activity): ActivityPreview;
@@ -24,7 +24,9 @@ export interface BaseActivity {
24
24
  direction: "inbound" | "outbound" | "internal" | "none";
25
25
  externalIds?: string[];
26
26
  attachments?: Attachment[];
27
- createdAt?: Date;
27
+ /** Epoch ms — matcht DB-model en Interaction.createdAt. */
28
+ createdAt?: number;
29
+ updatedAt?: number;
28
30
  }
29
31
  export type VoiceCallPayload = {
30
32
  from: string;
@@ -1,4 +1,13 @@
1
1
  import { Uri } from '../../platform/communication';
2
+ import { ActivityType } from '../activity/types';
3
+ export interface ActivityPreview {
4
+ activityId: string;
5
+ type: ActivityType;
6
+ snippet: string;
7
+ authorName: string;
8
+ direction: "inbound" | "outbound" | "internal" | "none";
9
+ createdAt: number;
10
+ }
2
11
  export interface InteractionSource {
3
12
  activityId?: string;
4
13
  activityType?: string;
@@ -36,4 +45,6 @@ export interface Interaction {
36
45
  visibility?: "visible" | "hidden";
37
46
  createdAt?: number;
38
47
  updatedAt?: number;
48
+ lastActivityAt?: number;
49
+ lastActivityPreview?: ActivityPreview;
39
50
  }
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(t){return t.endpoints??[]}const c=t=>!!t.assignedUserId||!!t.assignedInboxId,u=t=>t.status==="closed",p=t=>({urgent:10,high:5,normal:2,low:1})[t.priority]||0,g=(t,e=30)=>t.title?.length<=e?t.title:`${t.title.substring(0,e)}...`;function l(t,e){const s=new Set(t.disabledIntents??[]),i=t.intentOverrides??{},n=e.intents.filter(r=>!s.has(r.intent)).map(r=>I(r,i[r.intent]));if(!t.extraIntents||t.extraIntents.length===0)return n;const o=new Set(n.map(r=>r.intent));for(const r of t.extraIntents)o.has(r.intent)||(n.push(r),o.add(r.intent));return n}function I(t,e){return e?{intent:e.intent??t.intent,targetSchemes:e.targetSchemes??t.targetSchemes,transport:e.transport??t.transport}:t}function y(t,e){const s=[];for(const i of t){if(!i.enabled)continue;const n=e[i.providerId];if(n)for(const o of l(i,n))s.push({channel:i,description:n,capability:o})}return s}function E(t,e){return e.filter(s=>s.capability.intent===t)}function a(t,e){return e.filter(s=>s.capability.targetSchemes.includes(t))}function T(t,e){return a(t.scheme,e)}function b(t,e,s){const i=[];for(const n of t)for(const o of s)o.capability.intent===e&&o.capability.targetSchemes.includes(n.scheme)&&i.push({channelIntent:o,endpoint:n});return i}var f=(t=>(t.MAILTO="mailto",t.SIP="sip",t.TEL="tel",t.WEBHOOK="webhook",t.USERNAME="username",t.ID="id",t.CUSTOM="custom",t.URL="url",t.TELEGRAM="telegram",t.WHATSAPP="whatsapp",t.VIBER="viber",t.SMS="sms",t.FAX="fax",t.TEAMS="teams",t.CALENDAR="calendar",t))(f||{});const h=(t,e)=>({intent:t,...e}),S={ok:!1,code:"UNSUPPORTED",message:"Provider does not support this op"};exports.CommunicationScheme=f;exports.UNSUPPORTED=S;exports.buildChannelIntents=y;exports.defineIntent=h;exports.filterByEndpoint=T;exports.filterByIntent=E;exports.filterByTargetScheme=a;exports.getContactEndpoints=d;exports.getShortTitle=g;exports.getUrgencyScore=p;exports.isAssigned=c;exports.isClosed=u;exports.matchContactToIntents=b;exports.resolveChannelIntents=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=140;function c(e){return e.replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<[^>]+>/g," ").replace(/&nbsp;/g," ").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/\s+/g," ").trim()}function I(e){const t=e.trim();return t.length<=l?t:t.slice(0,l-1).trimEnd()+"…"}function E(e){if(!e||e<0)return"";const t=Math.floor(e/60),n=Math.floor(e%60);return`${t}:${n.toString().padStart(2,"0")}`}function A(e){switch(e.type){case"EMAIL_RECEIVED":case"EMAIL_SENT":{const t=e.payload,n=t.bodySnippet?.trim()||c(t.body??"");return t.subject?`${t.subject} — ${n}`:n}case"CHAT_MESSAGE_SENT":case"CHAT_MESSAGE_RECEIVED":return e.payload.text??"";case"CHAT_RENAMED":return`Hernoemd naar "${e.payload.newName}"`;case"CHAT_MEMBER_JOINED":return`${e.payload.members.map(t=>t.name).join(", ")} toegevoegd`;case"CHAT_MEMBER_LEFT":return`${e.payload.members.map(t=>t.name).join(", ")} verlaten`;case"CHAT_CALL_STARTED":return"Gesprek gestart";case"CHAT_CALL_ENDED":return`Gesprek beëindigd${e.payload.duration?` (${E(e.payload.duration)})`:""}`;case"CHAT_EVENT":return e.payload.text??e.payload.eventType;case"VOICE_CALL_STARTED":case"VIDEO_CALL_STARTED":return"Gesprek gestart";case"VOICE_CALL_ANSWERED":case"VIDEO_CALL_ANSWERED":return"Gesprek aangenomen";case"VOICE_CALL_HOLD":case"VIDEO_CALL_HOLD":return"In de wacht";case"VOICE_CALL_UNHOLD":case"VIDEO_CALL_UNHOLD":return"Hervat";case"VOICE_CALL_ENDED":case"VIDEO_CALL_ENDED":return`Gesprek beëindigd${e.payload.duration?` (${E(e.payload.duration)})`:""}`;case"VOICE_CALL_MISSED":case"VIDEO_CALL_MISSED":return"Gemiste oproep";case"VOICE_CALL_FAILED":case"VIDEO_CALL_FAILED":return"Gesprek mislukt";case"VOICE_CALL_VOICEMAIL":return e.payload.transcription?.trim()?e.payload.transcription:"Voicemail ontvangen";case"TRANSCRIPT_ADDED":return e.payload.text??"";case"AI_MESSAGE_ADDED":return e.payload.output?.text??e.payload.input?.text??"";case"MEETING_SCHEDULED":return`Vergadering gepland: ${e.payload.title}`;case"MEETING_STARTED":return`Vergadering gestart: ${e.payload.title}`;case"MEETING_ENDED":return`Vergadering beëindigd${e.payload.duration?` (${E(e.payload.duration)})`:""}`;case"MEETING_PARTICIPANT_JOINED":return`${e.payload.name} deelgenomen`;case"MEETING_PARTICIPANT_LEFT":return`${e.payload.name} verlaten`;case"COMMENT_ADDED":return e.payload.text??"";case"FILE_UPLOADED":return`Bestand: ${e.payload.fileName}`;case"INTERACTION_CREATED":return"Interactie aangemaakt";case"INTERACTION_STATUS_CHANGED":return`Status: ${e.payload.fromStatus} → ${e.payload.toStatus}`;case"INTERACTION_ASSIGNED":return"Interactie toegewezen";default:return""}}function i(e){return{activityId:e.id,type:e.type,snippet:I(A(e)),authorName:e.author?.name??"",direction:e.direction,createdAt:e.createdAt??Date.now()}}function _(e){return e.endpoints??[]}const g=e=>!!e.assignedUserId||!!e.assignedInboxId,T=e=>e.status==="closed",D=e=>({urgent:10,high:5,normal:2,low:1})[e.priority]||0,f=(e,t=30)=>e.title?.length<=t?e.title:`${e.title.substring(0,t)}...`;function p(e,t){const n=new Set(e.disabledIntents??[]),s=e.intentOverrides??{},r=t.intents.filter(a=>!n.has(a.intent)).map(a=>L(a,s[a.intent]));if(!e.extraIntents||e.extraIntents.length===0)return r;const o=new Set(r.map(a=>a.intent));for(const a of e.extraIntents)o.has(a.intent)||(r.push(a),o.add(a.intent));return r}function L(e,t){return t?{intent:t.intent??e.intent,targetSchemes:t.targetSchemes??e.targetSchemes,transport:t.transport??e.transport}:e}function C(e,t){const n=[];for(const s of e){if(!s.enabled)continue;const r=t[s.providerId];if(r)for(const o of p(s,r))n.push({channel:s,description:r,capability:o})}return n}function S(e,t){return t.filter(n=>n.capability.intent===e)}function d(e,t){return t.filter(n=>n.capability.targetSchemes.includes(e))}function N(e,t){return d(e.scheme,t)}function O(e,t,n){const s=[];for(const r of e)for(const o of n)o.capability.intent===t&&o.capability.targetSchemes.includes(r.scheme)&&s.push({channelIntent:o,endpoint:r});return s}var u=(e=>(e.MAILTO="mailto",e.SIP="sip",e.TEL="tel",e.WEBHOOK="webhook",e.USERNAME="username",e.ID="id",e.CUSTOM="custom",e.URL="url",e.TELEGRAM="telegram",e.WHATSAPP="whatsapp",e.VIBER="viber",e.SMS="sms",e.FAX="fax",e.TEAMS="teams",e.CALENDAR="calendar",e))(u||{});const M=(e,t)=>({intent:e,...t}),b={ok:!1,code:"UNSUPPORTED",message:"Provider does not support this op"};exports.CommunicationScheme=u;exports.UNSUPPORTED=b;exports.buildActivityPreview=i;exports.buildChannelIntents=C;exports.defineIntent=M;exports.filterByEndpoint=N;exports.filterByIntent=S;exports.filterByTargetScheme=d;exports.getContactEndpoints=_;exports.getShortTitle=f;exports.getUrgencyScore=D;exports.isAssigned=g;exports.isClosed=T;exports.matchContactToIntents=O;exports.resolveChannelIntents=p;
package/dist/index.js CHANGED
@@ -1,69 +1,165 @@
1
- function u(t) {
2
- return t.endpoints ?? [];
1
+ function p(e) {
2
+ return e.replace(/<style[\s\S]*?<\/style>/gi, " ").replace(/<script[\s\S]*?<\/script>/gi, " ").replace(/<[^>]+>/g, " ").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/\s+/g, " ").trim();
3
3
  }
4
- const p = (t) => !!t.assignedUserId || !!t.assignedInboxId, c = (t) => t.status === "closed", g = (t) => ({
4
+ function l(e) {
5
+ const t = e.trim();
6
+ return t.length <= 140 ? t : t.slice(0, 139).trimEnd() + "…";
7
+ }
8
+ function E(e) {
9
+ if (!e || e < 0) return "";
10
+ const t = Math.floor(e / 60), r = Math.floor(e % 60);
11
+ return `${t}:${r.toString().padStart(2, "0")}`;
12
+ }
13
+ function u(e) {
14
+ switch (e.type) {
15
+ case "EMAIL_RECEIVED":
16
+ case "EMAIL_SENT": {
17
+ const t = e.payload, r = t.bodySnippet?.trim() || p(t.body ?? "");
18
+ return t.subject ? `${t.subject} — ${r}` : r;
19
+ }
20
+ case "CHAT_MESSAGE_SENT":
21
+ case "CHAT_MESSAGE_RECEIVED":
22
+ return e.payload.text ?? "";
23
+ case "CHAT_RENAMED":
24
+ return `Hernoemd naar "${e.payload.newName}"`;
25
+ case "CHAT_MEMBER_JOINED":
26
+ return `${e.payload.members.map((t) => t.name).join(", ")} toegevoegd`;
27
+ case "CHAT_MEMBER_LEFT":
28
+ return `${e.payload.members.map((t) => t.name).join(", ")} verlaten`;
29
+ case "CHAT_CALL_STARTED":
30
+ return "Gesprek gestart";
31
+ case "CHAT_CALL_ENDED":
32
+ return `Gesprek beëindigd${e.payload.duration ? ` (${E(e.payload.duration)})` : ""}`;
33
+ case "CHAT_EVENT":
34
+ return e.payload.text ?? e.payload.eventType;
35
+ case "VOICE_CALL_STARTED":
36
+ case "VIDEO_CALL_STARTED":
37
+ return "Gesprek gestart";
38
+ case "VOICE_CALL_ANSWERED":
39
+ case "VIDEO_CALL_ANSWERED":
40
+ return "Gesprek aangenomen";
41
+ case "VOICE_CALL_HOLD":
42
+ case "VIDEO_CALL_HOLD":
43
+ return "In de wacht";
44
+ case "VOICE_CALL_UNHOLD":
45
+ case "VIDEO_CALL_UNHOLD":
46
+ return "Hervat";
47
+ case "VOICE_CALL_ENDED":
48
+ case "VIDEO_CALL_ENDED":
49
+ return `Gesprek beëindigd${e.payload.duration ? ` (${E(e.payload.duration)})` : ""}`;
50
+ case "VOICE_CALL_MISSED":
51
+ case "VIDEO_CALL_MISSED":
52
+ return "Gemiste oproep";
53
+ case "VOICE_CALL_FAILED":
54
+ case "VIDEO_CALL_FAILED":
55
+ return "Gesprek mislukt";
56
+ case "VOICE_CALL_VOICEMAIL":
57
+ return e.payload.transcription?.trim() ? e.payload.transcription : "Voicemail ontvangen";
58
+ case "TRANSCRIPT_ADDED":
59
+ return e.payload.text ?? "";
60
+ case "AI_MESSAGE_ADDED":
61
+ return e.payload.output?.text ?? e.payload.input?.text ?? "";
62
+ case "MEETING_SCHEDULED":
63
+ return `Vergadering gepland: ${e.payload.title}`;
64
+ case "MEETING_STARTED":
65
+ return `Vergadering gestart: ${e.payload.title}`;
66
+ case "MEETING_ENDED":
67
+ return `Vergadering beëindigd${e.payload.duration ? ` (${E(e.payload.duration)})` : ""}`;
68
+ case "MEETING_PARTICIPANT_JOINED":
69
+ return `${e.payload.name} deelgenomen`;
70
+ case "MEETING_PARTICIPANT_LEFT":
71
+ return `${e.payload.name} verlaten`;
72
+ case "COMMENT_ADDED":
73
+ return e.payload.text ?? "";
74
+ case "FILE_UPLOADED":
75
+ return `Bestand: ${e.payload.fileName}`;
76
+ case "INTERACTION_CREATED":
77
+ return "Interactie aangemaakt";
78
+ case "INTERACTION_STATUS_CHANGED":
79
+ return `Status: ${e.payload.fromStatus} → ${e.payload.toStatus}`;
80
+ case "INTERACTION_ASSIGNED":
81
+ return "Interactie toegewezen";
82
+ default:
83
+ return "";
84
+ }
85
+ }
86
+ function _(e) {
87
+ return {
88
+ activityId: e.id,
89
+ type: e.type,
90
+ snippet: l(u(e)),
91
+ authorName: e.author?.name ?? "",
92
+ direction: e.direction,
93
+ createdAt: e.createdAt ?? Date.now()
94
+ };
95
+ }
96
+ function T(e) {
97
+ return e.endpoints ?? [];
98
+ }
99
+ const D = (e) => !!e.assignedUserId || !!e.assignedInboxId, g = (e) => e.status === "closed", L = (e) => ({
5
100
  urgent: 10,
6
101
  high: 5,
7
102
  normal: 2,
8
103
  low: 1
9
- })[t.priority] || 0, I = (t, n = 30) => t.title?.length <= n ? t.title : `${t.title.substring(0, n)}...`;
10
- function f(t, n) {
11
- const s = new Set(t.disabledIntents ?? []), i = t.intentOverrides ?? {}, e = n.intents.filter((r) => !s.has(r.intent)).map((r) => l(r, i[r.intent]));
12
- if (!t.extraIntents || t.extraIntents.length === 0) return e;
13
- const o = new Set(e.map((r) => r.intent));
14
- for (const r of t.extraIntents)
15
- o.has(r.intent) || (e.push(r), o.add(r.intent));
16
- return e;
104
+ })[e.priority] || 0, f = (e, t = 30) => e.title?.length <= t ? e.title : `${e.title.substring(0, t)}...`;
105
+ function d(e, t) {
106
+ const r = new Set(e.disabledIntents ?? []), s = e.intentOverrides ?? {}, n = t.intents.filter((a) => !r.has(a.intent)).map((a) => A(a, s[a.intent]));
107
+ if (!e.extraIntents || e.extraIntents.length === 0) return n;
108
+ const o = new Set(n.map((a) => a.intent));
109
+ for (const a of e.extraIntents)
110
+ o.has(a.intent) || (n.push(a), o.add(a.intent));
111
+ return n;
17
112
  }
18
- function l(t, n) {
19
- return n ? {
20
- intent: n.intent ?? t.intent,
21
- targetSchemes: n.targetSchemes ?? t.targetSchemes,
22
- transport: n.transport ?? t.transport
23
- } : t;
113
+ function A(e, t) {
114
+ return t ? {
115
+ intent: t.intent ?? e.intent,
116
+ targetSchemes: t.targetSchemes ?? e.targetSchemes,
117
+ transport: t.transport ?? e.transport
118
+ } : e;
24
119
  }
25
- function E(t, n) {
26
- const s = [];
27
- for (const i of t) {
28
- if (!i.enabled) continue;
29
- const e = n[i.providerId];
30
- if (e)
31
- for (const o of f(i, e))
32
- s.push({ channel: i, description: e, capability: o });
120
+ function i(e, t) {
121
+ const r = [];
122
+ for (const s of e) {
123
+ if (!s.enabled) continue;
124
+ const n = t[s.providerId];
125
+ if (n)
126
+ for (const o of d(s, n))
127
+ r.push({ channel: s, description: n, capability: o });
33
128
  }
34
- return s;
129
+ return r;
35
130
  }
36
- function b(t, n) {
37
- return n.filter((s) => s.capability.intent === t);
131
+ function N(e, t) {
132
+ return t.filter((r) => r.capability.intent === e);
38
133
  }
39
- function a(t, n) {
40
- return n.filter((s) => s.capability.targetSchemes.includes(t));
134
+ function I(e, t) {
135
+ return t.filter((r) => r.capability.targetSchemes.includes(e));
41
136
  }
42
- function T(t, n) {
43
- return a(t.scheme, n);
137
+ function S(e, t) {
138
+ return I(e.scheme, t);
44
139
  }
45
- function y(t, n, s) {
46
- const i = [];
47
- for (const e of t)
48
- for (const o of s)
49
- o.capability.intent === n && o.capability.targetSchemes.includes(e.scheme) && i.push({ channelIntent: o, endpoint: e });
50
- return i;
140
+ function C(e, t, r) {
141
+ const s = [];
142
+ for (const n of e)
143
+ for (const o of r)
144
+ o.capability.intent === t && o.capability.targetSchemes.includes(n.scheme) && s.push({ channelIntent: o, endpoint: n });
145
+ return s;
51
146
  }
52
- var d = /* @__PURE__ */ ((t) => (t.MAILTO = "mailto", t.SIP = "sip", t.TEL = "tel", t.WEBHOOK = "webhook", t.USERNAME = "username", t.ID = "id", t.CUSTOM = "custom", t.URL = "url", t.TELEGRAM = "telegram", t.WHATSAPP = "whatsapp", t.VIBER = "viber", t.SMS = "sms", t.FAX = "fax", t.TEAMS = "teams", t.CALENDAR = "calendar", t))(d || {});
53
- const A = (t, n) => ({ intent: t, ...n }), U = { ok: !1, code: "UNSUPPORTED", message: "Provider does not support this op" };
147
+ var c = /* @__PURE__ */ ((e) => (e.MAILTO = "mailto", e.SIP = "sip", e.TEL = "tel", e.WEBHOOK = "webhook", e.USERNAME = "username", e.ID = "id", e.CUSTOM = "custom", e.URL = "url", e.TELEGRAM = "telegram", e.WHATSAPP = "whatsapp", e.VIBER = "viber", e.SMS = "sms", e.FAX = "fax", e.TEAMS = "teams", e.CALENDAR = "calendar", e))(c || {});
148
+ const O = (e, t) => ({ intent: e, ...t }), M = { ok: !1, code: "UNSUPPORTED", message: "Provider does not support this op" };
54
149
  export {
55
- d as CommunicationScheme,
56
- U as UNSUPPORTED,
57
- E as buildChannelIntents,
58
- A as defineIntent,
59
- T as filterByEndpoint,
60
- b as filterByIntent,
61
- a as filterByTargetScheme,
62
- u as getContactEndpoints,
63
- I as getShortTitle,
64
- g as getUrgencyScore,
65
- p as isAssigned,
66
- c as isClosed,
67
- y as matchContactToIntents,
68
- f as resolveChannelIntents
150
+ c as CommunicationScheme,
151
+ M as UNSUPPORTED,
152
+ _ as buildActivityPreview,
153
+ i as buildChannelIntents,
154
+ O as defineIntent,
155
+ S as filterByEndpoint,
156
+ N as filterByIntent,
157
+ I as filterByTargetScheme,
158
+ T as getContactEndpoints,
159
+ f as getShortTitle,
160
+ L as getUrgencyScore,
161
+ D as isAssigned,
162
+ g as isClosed,
163
+ C as matchContactToIntents,
164
+ d as resolveChannelIntents
69
165
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencxh/domain",
3
- "version": "1.29.0",
3
+ "version": "1.31.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",