@opencxh/domain 1.16.0 → 1.17.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.
@@ -0,0 +1,6 @@
1
+ import { Contact, ContactEndpoint } from './types';
2
+ /**
3
+ * Returns the contact's communication endpoints, synthesising them from
4
+ * legacy phone/email fields when `endpoints` is not populated yet.
5
+ */
6
+ export declare function getContactEndpoints(contact: Contact): ContactEndpoint[];
@@ -1 +1,2 @@
1
1
  export * from './types';
2
+ export * from './endpoints';
@@ -1,3 +1,10 @@
1
+ import { CommunicationScheme } from '../../platform/communication';
2
+ export interface ContactEndpoint {
3
+ scheme: CommunicationScheme;
4
+ resource: string;
5
+ label?: string;
6
+ primary?: boolean;
7
+ }
1
8
  /**
2
9
  * Data model for a single Contact.
3
10
  */
@@ -10,4 +17,5 @@ export interface Contact {
10
17
  email?: string;
11
18
  phone?: string;
12
19
  address?: string;
20
+ endpoints?: ContactEndpoint[];
13
21
  }
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=s=>!!s.assignedUserId||!!s.assignedInboxId,l=s=>s.status==="closed",g=s=>({urgent:10,high:5,normal:2,low:1})[s.priority]||0,d=(s,r=30)=>s.title.length<=r?s.title:`${s.title.substring(0,r)}...`;var t=(s=>(s.MAILTO="mailto",s.SIP="sip",s.TEL="tel",s.WEBHOOK="webhook",s.USERNAME="username",s.ID="id",s.CUSTOM="custom",s.URL="url",s.TELEGRAM="telegram",s.WHATSAPP="whatsapp",s.VIBER="viber",s.SMS="sms",s.FAX="fax",s.TEAMS="teams",s))(t||{});exports.CommunicationScheme=t;exports.getShortTitle=d;exports.getUrgencyScore=g;exports.isAssigned=e;exports.isClosed=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(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))(t||{});function d(e){if(e.endpoints&&e.endpoints.length>0)return e.endpoints;const s=[];return e.phone&&s.push({scheme:t.TEL,resource:e.phone,primary:!0}),e.email&&s.push({scheme:t.MAILTO,resource:e.email,primary:!e.phone}),s}const p=e=>!!e.assignedUserId||!!e.assignedInboxId,a=e=>e.status==="closed",f=e=>({urgent:10,high:5,normal:2,low:1})[e.priority]||0,g=(e,s=30)=>e.title.length<=s?e.title:`${e.title.substring(0,s)}...`,c={[t.TEL]:["call"],[t.SIP]:["call"],[t.MAILTO]:["mail"],[t.SMS]:["message"],[t.WHATSAPP]:["message"],[t.TELEGRAM]:["message"],[t.VIBER]:["message"],[t.TEAMS]:["call","message","video"],[t.FAX]:["message"]},E=["call","mail","message","video"];function l(e,s){if(!e.supportedSchemes.includes(s))return[];const n=e.capabilities.filter(r=>r.scheme===s&&r.value===!0&&E.includes(r.key));return n.length>0?n.map(r=>r.key):c[s]??[]}function u(e){const s=new Set;for(const n of e.supportedSchemes)for(const r of l(e,n))s.add(r);return Array.from(s)}function T(e,s){return Object.entries(e).map(([n,r])=>({providerId:n,description:r,intents:u(r)}))}function A(e,s){return s.filter(n=>n.intents.includes(e))}function v(e,s){return s.filter(n=>n.description.supportedSchemes.includes(e.scheme))}function I(e,s,n){const r=[];for(const o of e)for(const i of n)i.description.supportedSchemes.includes(o.scheme)&&l(i.description,o.scheme).includes(s)&&r.push({capability:i,endpoint:o});return r}exports.CommunicationScheme=t;exports.buildResolvedCapabilities=T;exports.getContactEndpoints=d;exports.getShortTitle=g;exports.getUrgencyScore=f;exports.intentsForProvider=u;exports.intentsForScheme=l;exports.isAssigned=p;exports.isClosed=a;exports.resolveForContact=I;exports.resolveForEndpoint=v;exports.resolveForIntent=A;
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * from './entities/transcript';
17
17
  export * from './entities/user';
18
18
  export * from './platform/api';
19
19
  export * from './platform/common';
20
+ export * from './platform/capabilities';
20
21
  export * from './platform/communication';
21
22
  export * from './platform/federated';
22
23
  export * from './platform/intents';
package/dist/index.js CHANGED
@@ -1,14 +1,70 @@
1
- const l = (s) => !!s.assignedUserId || !!s.assignedInboxId, g = (s) => s.status === "closed", d = (s) => ({
1
+ var n = /* @__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))(n || {});
2
+ function f(e) {
3
+ if (e.endpoints && e.endpoints.length > 0)
4
+ return e.endpoints;
5
+ const s = [];
6
+ return e.phone && s.push({ scheme: n.TEL, resource: e.phone, primary: !0 }), e.email && s.push({ scheme: n.MAILTO, resource: e.email, primary: !e.phone }), s;
7
+ }
8
+ const a = (e) => !!e.assignedUserId || !!e.assignedInboxId, g = (e) => e.status === "closed", E = (e) => ({
2
9
  urgent: 10,
3
10
  high: 5,
4
11
  normal: 2,
5
12
  low: 1
6
- })[s.priority] || 0, A = (s, r = 30) => s.title.length <= r ? s.title : `${s.title.substring(0, r)}...`;
7
- var t = /* @__PURE__ */ ((s) => (s.MAILTO = "mailto", s.SIP = "sip", s.TEL = "tel", s.WEBHOOK = "webhook", s.USERNAME = "username", s.ID = "id", s.CUSTOM = "custom", s.URL = "url", s.TELEGRAM = "telegram", s.WHATSAPP = "whatsapp", s.VIBER = "viber", s.SMS = "sms", s.FAX = "fax", s.TEAMS = "teams", s))(t || {});
13
+ })[e.priority] || 0, T = (e, s = 30) => e.title.length <= s ? e.title : `${e.title.substring(0, s)}...`, u = {
14
+ [n.TEL]: ["call"],
15
+ [n.SIP]: ["call"],
16
+ [n.MAILTO]: ["mail"],
17
+ [n.SMS]: ["message"],
18
+ [n.WHATSAPP]: ["message"],
19
+ [n.TELEGRAM]: ["message"],
20
+ [n.VIBER]: ["message"],
21
+ [n.TEAMS]: ["call", "message", "video"],
22
+ [n.FAX]: ["message"]
23
+ }, d = ["call", "mail", "message", "video"];
24
+ function i(e, s) {
25
+ if (!e.supportedSchemes.includes(s)) return [];
26
+ const t = e.capabilities.filter(
27
+ (r) => r.scheme === s && r.value === !0 && d.includes(r.key)
28
+ );
29
+ return t.length > 0 ? t.map((r) => r.key) : u[s] ?? [];
30
+ }
31
+ function p(e) {
32
+ const s = /* @__PURE__ */ new Set();
33
+ for (const t of e.supportedSchemes)
34
+ for (const r of i(e, t)) s.add(r);
35
+ return Array.from(s);
36
+ }
37
+ function c(e, s) {
38
+ return Object.entries(e).map(([t, r]) => ({
39
+ providerId: t,
40
+ description: r,
41
+ intents: p(r)
42
+ }));
43
+ }
44
+ function A(e, s) {
45
+ return s.filter((t) => t.intents.includes(e));
46
+ }
47
+ function I(e, s) {
48
+ return s.filter((t) => t.description.supportedSchemes.includes(e.scheme));
49
+ }
50
+ function h(e, s, t) {
51
+ const r = [];
52
+ for (const l of e)
53
+ for (const o of t)
54
+ o.description.supportedSchemes.includes(l.scheme) && i(o.description, l.scheme).includes(s) && r.push({ capability: o, endpoint: l });
55
+ return r;
56
+ }
8
57
  export {
9
- t as CommunicationScheme,
10
- A as getShortTitle,
11
- d as getUrgencyScore,
12
- l as isAssigned,
13
- g as isClosed
58
+ n as CommunicationScheme,
59
+ c as buildResolvedCapabilities,
60
+ f as getContactEndpoints,
61
+ T as getShortTitle,
62
+ E as getUrgencyScore,
63
+ p as intentsForProvider,
64
+ i as intentsForScheme,
65
+ a as isAssigned,
66
+ g as isClosed,
67
+ h as resolveForContact,
68
+ I as resolveForEndpoint,
69
+ A as resolveForIntent
14
70
  };
@@ -0,0 +1,31 @@
1
+ import { ContactEndpoint } from '../entities/contact/types';
2
+ import { CommsAccount, CommunicationScheme, ProviderDescription, Uri } from './communication';
3
+ export type CommunicationIntent = "call" | "mail" | "message" | "video";
4
+ export interface ResolvedCapability {
5
+ providerId: string;
6
+ description: ProviderDescription;
7
+ intents: CommunicationIntent[];
8
+ }
9
+ export interface ResolvedCapabilityMatch {
10
+ capability: ResolvedCapability;
11
+ endpoint: ContactEndpoint;
12
+ }
13
+ /**
14
+ * Returns which intents a provider offers for a given scheme.
15
+ *
16
+ * Capability rows whose `key` is a known user-intent (`call|mail|message|video`)
17
+ * are treated as explicit declarations. Anything else (e.g. `call_forward`,
18
+ * `call_hold` — those are session-action feature flags) is ignored here.
19
+ *
20
+ * When a scheme has no explicit intent rows, the conventional default
21
+ * mapping kicks in so providers can ship just `supportedSchemes`.
22
+ */
23
+ export declare function intentsForScheme(description: ProviderDescription, scheme: CommunicationScheme): CommunicationIntent[];
24
+ /**
25
+ * Unions intents across all schemes a provider supports.
26
+ */
27
+ export declare function intentsForProvider(description: ProviderDescription): CommunicationIntent[];
28
+ export declare function buildResolvedCapabilities(descriptions: Record<string, ProviderDescription>, _accounts?: CommsAccount[]): ResolvedCapability[];
29
+ export declare function resolveForIntent(intent: CommunicationIntent, capabilities: ResolvedCapability[]): ResolvedCapability[];
30
+ export declare function resolveForEndpoint(uri: Uri, capabilities: ResolvedCapability[]): ResolvedCapability[];
31
+ export declare function resolveForContact(endpoints: ContactEndpoint[], intent: CommunicationIntent, capabilities: ResolvedCapability[]): ResolvedCapabilityMatch[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencxh/domain",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",