@opencxh/domain 1.36.0 → 1.38.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,2 +1,3 @@
1
1
  export * from './types';
2
2
  export * from './logic';
3
+ export * from './seen';
@@ -0,0 +1,2 @@
1
+ import { Interaction } from './types';
2
+ export declare function isInteractionUnseen(interaction: Interaction, userId: string): boolean;
@@ -40,6 +40,7 @@ export interface Interaction {
40
40
  links: InteractionLink[];
41
41
  externalIds?: string[];
42
42
  collaborators: string[];
43
+ seenBy?: string[];
43
44
  assignedUserId?: string;
44
45
  ticketId?: string;
45
46
  visibility?: "visible" | "hidden";
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=140;function p(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()||p(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.segments??[]).map(t=>t.text).join(" ");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 d(e,t){const n=new Set(e.disabledIntents??[]),a=e.intentOverrides??{},r=t.intents.filter(s=>!n.has(s.intent)).map(s=>L(s,a[s.intent]));if(!e.extraIntents||e.extraIntents.length===0)return r;const o=new Set(r.map(s=>s.intent));for(const s of e.extraIntents)o.has(s.intent)||(r.push(s),o.add(s.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 a of e){if(!a.enabled)continue;const r=t[a.providerId];if(r)for(const o of d(a,r))n.push({channel:a,description:r,capability:o})}return n}function S(e,t){return t.filter(n=>n.capability.intent===e)}function u(e,t){return t.filter(n=>n.capability.targetSchemes.includes(e))}function N(e,t){return u(e.scheme,t)}function O(e,t,n){const a=[];for(const r of e)for(const o of n)o.capability.intent===t&&o.capability.targetSchemes.includes(r.scheme)&&a.push({channelIntent:o,endpoint:r});return a}var c=(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||{});const M=(e,t)=>({intent:e,...t}),b={ok:!1,code:"UNSUPPORTED",message:"Provider does not support this op"};exports.CommunicationScheme=c;exports.UNSUPPORTED=b;exports.buildActivityPreview=i;exports.buildChannelIntents=C;exports.defineIntent=M;exports.filterByEndpoint=N;exports.filterByIntent=S;exports.filterByTargetScheme=u;exports.getContactEndpoints=_;exports.getShortTitle=f;exports.getUrgencyScore=D;exports.isAssigned=g;exports.isClosed=T;exports.matchContactToIntents=O;exports.resolveChannelIntents=d;exports.stripHtml=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=140;function p(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 i(e){switch(e.type){case"EMAIL_RECEIVED":case"EMAIL_SENT":{const t=e.payload,n=t.bodySnippet?.trim()||p(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.segments??[]).map(t=>t.text).join(" ");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 A(e){return{activityId:e.id,type:e.type,snippet:I(i(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 L(e,t){return e.lastActivityAt?!(e.seenBy??[]).includes(t):!1}function u(e,t){const n=new Set(e.disabledIntents??[]),a=e.intentOverrides??{},r=t.intents.filter(s=>!n.has(s.intent)).map(s=>C(s,a[s.intent]));if(!e.extraIntents||e.extraIntents.length===0)return r;const o=new Set(r.map(s=>s.intent));for(const s of e.extraIntents)o.has(s.intent)||(r.push(s),o.add(s.intent));return r}function C(e,t){return t?{intent:t.intent??e.intent,targetSchemes:t.targetSchemes??e.targetSchemes,transport:t.transport??e.transport}:e}function S(e,t){const n=[];for(const a of e){if(!a.enabled)continue;const r=t[a.providerId];if(r)for(const o of u(a,r))n.push({channel:a,description:r,capability:o})}return n}function N(e,t){return t.filter(n=>n.capability.intent===e)}function d(e,t){return t.filter(n=>n.capability.targetSchemes.includes(e))}function O(e,t){return d(e.scheme,t)}function M(e,t,n){const a=[];for(const r of e)for(const o of n)o.capability.intent===t&&o.capability.targetSchemes.includes(r.scheme)&&a.push({channelIntent:o,endpoint:r});return a}var c=(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||{});const b=(e,t)=>({intent:e,...t}),R={ok:!1,code:"UNSUPPORTED",message:"Provider does not support this op"};exports.CommunicationScheme=c;exports.UNSUPPORTED=R;exports.buildActivityPreview=A;exports.buildChannelIntents=S;exports.defineIntent=b;exports.filterByEndpoint=O;exports.filterByIntent=N;exports.filterByTargetScheme=d;exports.getContactEndpoints=_;exports.getShortTitle=f;exports.getUrgencyScore=D;exports.isAssigned=g;exports.isClosed=T;exports.isInteractionUnseen=L;exports.matchContactToIntents=M;exports.resolveChannelIntents=u;exports.stripHtml=p;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  function p(e) {
2
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
- function l(e) {
4
+ function u(e) {
5
5
  const t = e.trim();
6
6
  return t.length <= 140 ? t : t.slice(0, 139).trimEnd() + "…";
7
7
  }
@@ -10,7 +10,7 @@ function E(e) {
10
10
  const t = Math.floor(e / 60), r = Math.floor(e % 60);
11
11
  return `${t}:${r.toString().padStart(2, "0")}`;
12
12
  }
13
- function u(e) {
13
+ function l(e) {
14
14
  switch (e.type) {
15
15
  case "EMAIL_RECEIVED":
16
16
  case "EMAIL_SENT": {
@@ -87,7 +87,7 @@ function _(e) {
87
87
  return {
88
88
  activityId: e.id,
89
89
  type: e.type,
90
- snippet: l(u(e)),
90
+ snippet: u(l(e)),
91
91
  authorName: e.author?.name ?? "",
92
92
  direction: e.direction,
93
93
  createdAt: e.createdAt ?? Date.now()
@@ -96,18 +96,21 @@ function _(e) {
96
96
  function T(e) {
97
97
  return e.endpoints ?? [];
98
98
  }
99
- const D = (e) => !!e.assignedUserId || !!e.assignedInboxId, g = (e) => e.status === "closed", L = (e) => ({
99
+ const D = (e) => !!e.assignedUserId || !!e.assignedInboxId, g = (e) => e.status === "closed", i = (e) => ({
100
100
  urgent: 10,
101
101
  high: 5,
102
102
  normal: 2,
103
103
  low: 1
104
- })[e.priority] || 0, i = (e, t = 30) => e.title?.length <= t ? e.title : `${e.title.substring(0, t)}...`;
104
+ })[e.priority] || 0, L = (e, t = 30) => e.title?.length <= t ? e.title : `${e.title.substring(0, t)}...`;
105
+ function f(e, t) {
106
+ return e.lastActivityAt ? !(e.seenBy ?? []).includes(t) : !1;
107
+ }
105
108
  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]));
109
+ const r = new Set(e.disabledIntents ?? []), a = e.intentOverrides ?? {}, n = t.intents.filter((s) => !r.has(s.intent)).map((s) => A(s, a[s.intent]));
107
110
  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
+ const o = new Set(n.map((s) => s.intent));
112
+ for (const s of e.extraIntents)
113
+ o.has(s.intent) || (n.push(s), o.add(s.intent));
111
114
  return n;
112
115
  }
113
116
  function A(e, t) {
@@ -117,50 +120,51 @@ function A(e, t) {
117
120
  transport: t.transport ?? e.transport
118
121
  } : e;
119
122
  }
120
- function f(e, t) {
123
+ function N(e, t) {
121
124
  const r = [];
122
- for (const s of e) {
123
- if (!s.enabled) continue;
124
- const n = t[s.providerId];
125
+ for (const a of e) {
126
+ if (!a.enabled) continue;
127
+ const n = t[a.providerId];
125
128
  if (n)
126
- for (const o of d(s, n))
127
- r.push({ channel: s, description: n, capability: o });
129
+ for (const o of d(a, n))
130
+ r.push({ channel: a, description: n, capability: o });
128
131
  }
129
132
  return r;
130
133
  }
131
- function N(e, t) {
134
+ function S(e, t) {
132
135
  return t.filter((r) => r.capability.intent === e);
133
136
  }
134
137
  function I(e, t) {
135
138
  return t.filter((r) => r.capability.targetSchemes.includes(e));
136
139
  }
137
- function S(e, t) {
140
+ function C(e, t) {
138
141
  return I(e.scheme, t);
139
142
  }
140
- function C(e, t, r) {
141
- const s = [];
143
+ function O(e, t, r) {
144
+ const a = [];
142
145
  for (const n of e)
143
146
  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;
147
+ o.capability.intent === t && o.capability.targetSchemes.includes(n.scheme) && a.push({ channelIntent: o, endpoint: n });
148
+ return a;
146
149
  }
147
150
  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" };
151
+ const M = (e, t) => ({ intent: e, ...t }), R = { ok: !1, code: "UNSUPPORTED", message: "Provider does not support this op" };
149
152
  export {
150
153
  c as CommunicationScheme,
151
- M as UNSUPPORTED,
154
+ R as UNSUPPORTED,
152
155
  _ as buildActivityPreview,
153
- f as buildChannelIntents,
154
- O as defineIntent,
155
- S as filterByEndpoint,
156
- N as filterByIntent,
156
+ N as buildChannelIntents,
157
+ M as defineIntent,
158
+ C as filterByEndpoint,
159
+ S as filterByIntent,
157
160
  I as filterByTargetScheme,
158
161
  T as getContactEndpoints,
159
- i as getShortTitle,
160
- L as getUrgencyScore,
162
+ L as getShortTitle,
163
+ i as getUrgencyScore,
161
164
  D as isAssigned,
162
165
  g as isClosed,
163
- C as matchContactToIntents,
166
+ f as isInteractionUnseen,
167
+ O as matchContactToIntents,
164
168
  d as resolveChannelIntents,
165
169
  p as stripHtml
166
170
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencxh/domain",
3
- "version": "1.36.0",
3
+ "version": "1.38.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",