@escalated-dev/escalated 0.6.0 → 0.7.1

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.
Files changed (187) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +125 -2
  3. package/package.json +40 -5
  4. package/src/components/ActiveChatsPanel.vue +246 -0
  5. package/src/components/ActivityTimeline.stories.js +55 -0
  6. package/src/components/ActivityTimeline.vue +83 -66
  7. package/src/components/AdminDashboard.stories.js +1423 -0
  8. package/src/components/AgentLoadIndicator.stories.js +37 -0
  9. package/src/components/AgentLoadIndicator.vue +49 -0
  10. package/src/components/AgentPerformanceCard.vue +44 -0
  11. package/src/components/ArticleEditor.vue +82 -0
  12. package/src/components/AssigneeSelect.vue +37 -23
  13. package/src/components/AttachmentList.vue +65 -37
  14. package/src/components/AuditLogEntry.vue +95 -0
  15. package/src/components/BulkActionBar.vue +166 -97
  16. package/src/components/CategoryTree.vue +89 -0
  17. package/src/components/ChartWidget.vue +46 -0
  18. package/src/components/ChatActionBar.vue +226 -0
  19. package/src/components/ChatBubble.vue +162 -0
  20. package/src/components/ChatComposer.vue +308 -0
  21. package/src/components/ChatQueue.vue +222 -0
  22. package/src/components/ChatThread.vue +197 -0
  23. package/src/components/CollisionWarning.stories.js +30 -0
  24. package/src/components/CollisionWarning.vue +68 -0
  25. package/src/components/ConditionalFieldRules.vue +135 -0
  26. package/src/components/ContextPanel.vue +66 -0
  27. package/src/components/ContextPanelSection.vue +65 -0
  28. package/src/components/CustomFieldRenderer.vue +159 -0
  29. package/src/components/EscalatedLayout.vue +424 -70
  30. package/src/components/FileDropzone.vue +57 -41
  31. package/src/components/FollowButton.stories.js +30 -0
  32. package/src/components/FollowButton.vue +88 -63
  33. package/src/components/KeyboardShortcutHelp.vue +213 -123
  34. package/src/components/KnowledgePanel.vue +122 -0
  35. package/src/components/KpiCard.stories.js +32 -0
  36. package/src/components/KpiCard.vue +88 -0
  37. package/src/components/MacroDropdown.vue +150 -90
  38. package/src/components/MentionDropdown.vue +154 -0
  39. package/src/components/MetricComparison.vue +89 -0
  40. package/src/components/PercentileChart.vue +67 -0
  41. package/src/components/PeriodSelector.vue +98 -0
  42. package/src/components/PermissionMatrix.vue +107 -0
  43. package/src/components/PinnedNotes.vue +129 -90
  44. package/src/components/PluginSlot.vue +68 -62
  45. package/src/components/PresenceIndicator.vue +138 -28
  46. package/src/components/PriorityBadge.stories.js +33 -0
  47. package/src/components/PriorityBadge.vue +46 -39
  48. package/src/components/QuickFilters.vue +65 -49
  49. package/src/components/ReplyComposer.vue +207 -30
  50. package/src/components/ReplyThread.vue +111 -21
  51. package/src/components/ReportChart.vue +395 -0
  52. package/src/components/ReportExportButton.vue +108 -0
  53. package/src/components/SatisfactionRating.vue +180 -128
  54. package/src/components/SaveViewDialog.vue +172 -0
  55. package/src/components/SavedViewSidebar.vue +208 -0
  56. package/src/components/ScheduleEditor.vue +104 -0
  57. package/src/components/SideConversation.vue +165 -0
  58. package/src/components/SideConversationList.vue +147 -0
  59. package/src/components/SkillTagManager.vue +79 -0
  60. package/src/components/SlaComplianceChart.vue +46 -0
  61. package/src/components/SlaTimer.stories.js +35 -0
  62. package/src/components/SlaTimer.vue +62 -49
  63. package/src/components/SnoozeButton.vue +247 -0
  64. package/src/components/StatsCard.stories.js +24 -0
  65. package/src/components/StatsCard.vue +18 -6
  66. package/src/components/StatusBadge.stories.js +53 -0
  67. package/src/components/StatusBadge.vue +78 -46
  68. package/src/components/TagSelect.vue +84 -53
  69. package/src/components/TicketFilters.vue +247 -46
  70. package/src/components/TicketLinkPanel.vue +193 -0
  71. package/src/components/TicketList.vue +536 -74
  72. package/src/components/TicketMergeDialog.vue +157 -0
  73. package/src/components/TicketSidebar.vue +167 -99
  74. package/src/components/TicketSplitDialog.vue +98 -0
  75. package/src/components/TicketTypeSelector.vue +21 -0
  76. package/src/components/TotpInput.stories.js +9 -0
  77. package/src/components/TotpInput.vue +81 -0
  78. package/src/components/TwoFactorSetup.vue +113 -0
  79. package/src/components/VariableTokenInput.vue +111 -0
  80. package/src/components/WorkflowActionConfig.vue +287 -0
  81. package/src/components/WorkflowActionList.vue +350 -0
  82. package/src/components/WorkflowConditionBuilder.vue +265 -0
  83. package/src/components/WorkflowTriggerSelector.vue +125 -0
  84. package/src/composables/useChat.js +187 -0
  85. package/src/composables/useDebouncedSearch.js +38 -0
  86. package/src/composables/useI18n.js +80 -80
  87. package/src/composables/useKeyboardShortcuts.js +46 -46
  88. package/src/composables/useMentions.js +134 -0
  89. package/src/composables/usePluginExtensions.js +159 -67
  90. package/src/composables/usePluginHooks.js +65 -0
  91. package/src/composables/useRealtime.js +182 -0
  92. package/src/defineEscalatedPlugin.js +76 -50
  93. package/src/index.js +77 -28
  94. package/src/locales/ar.json +727 -0
  95. package/src/locales/de.json +678 -430
  96. package/src/locales/en.json +717 -430
  97. package/src/locales/es.json +679 -430
  98. package/src/locales/fr.json +680 -431
  99. package/src/locales/index.js +12 -2
  100. package/src/locales/it.json +727 -0
  101. package/src/locales/ja.json +727 -0
  102. package/src/locales/ko.json +727 -0
  103. package/src/locales/nl.json +727 -0
  104. package/src/locales/pl.json +727 -0
  105. package/src/locales/pt-BR.json +727 -0
  106. package/src/locales/ru.json +727 -0
  107. package/src/locales/tr.json +727 -0
  108. package/src/locales/zh-CN.json +727 -0
  109. package/src/pages/Admin/ApiTokens/Index.vue +381 -217
  110. package/src/pages/Admin/AuditLog/Index.vue +154 -0
  111. package/src/pages/Admin/BusinessHours/Form.vue +172 -0
  112. package/src/pages/Admin/BusinessHours/Index.vue +113 -0
  113. package/src/pages/Admin/CannedResponses/Index.vue +82 -25
  114. package/src/pages/Admin/Capacity/Index.vue +134 -0
  115. package/src/pages/Admin/CustomFields/Form.vue +195 -0
  116. package/src/pages/Admin/CustomFields/Index.vue +134 -0
  117. package/src/pages/Admin/CustomObjects/Form.vue +202 -0
  118. package/src/pages/Admin/CustomObjects/Index.vue +127 -0
  119. package/src/pages/Admin/CustomObjects/Records.vue +228 -0
  120. package/src/pages/Admin/Departments/Form.vue +35 -11
  121. package/src/pages/Admin/Departments/Index.vue +74 -21
  122. package/src/pages/Admin/EscalationRules/Form.vue +86 -25
  123. package/src/pages/Admin/EscalationRules/Index.vue +158 -37
  124. package/src/pages/Admin/Import/Connect.vue +95 -0
  125. package/src/pages/Admin/Import/Index.vue +102 -0
  126. package/src/pages/Admin/Import/Mapping.vue +110 -0
  127. package/src/pages/Admin/Import/Progress.vue +153 -0
  128. package/src/pages/Admin/Import/Review.vue +76 -0
  129. package/src/pages/Admin/KnowledgeBase/Articles/Form.vue +142 -0
  130. package/src/pages/Admin/KnowledgeBase/Articles/Index.vue +195 -0
  131. package/src/pages/Admin/KnowledgeBase/Categories/Index.vue +193 -0
  132. package/src/pages/Admin/Macros/Index.vue +448 -287
  133. package/src/pages/Admin/Plugins/Index.vue +327 -197
  134. package/src/pages/Admin/Reports/AgentDetail.vue +132 -0
  135. package/src/pages/Admin/Reports/AgentMetrics.vue +115 -0
  136. package/src/pages/Admin/Reports/AgentRanking.vue +246 -0
  137. package/src/pages/Admin/Reports/Cohorts.vue +180 -0
  138. package/src/pages/Admin/Reports/Comparison.vue +141 -0
  139. package/src/pages/Admin/Reports/CsatReport.vue +127 -0
  140. package/src/pages/Admin/Reports/Dashboard.vue +226 -0
  141. package/src/pages/Admin/Reports/ResolutionTimes.vue +164 -0
  142. package/src/pages/Admin/Reports/ResponseTimes.vue +164 -0
  143. package/src/pages/Admin/Reports/SlaReport.vue +162 -0
  144. package/src/pages/Admin/Reports/SlaTrends.vue +183 -0
  145. package/src/pages/Admin/Reports.vue +206 -101
  146. package/src/pages/Admin/Roles/Form.vue +71 -0
  147. package/src/pages/Admin/Roles/Index.vue +122 -0
  148. package/src/pages/Admin/Settings/CsatSettings.vue +165 -0
  149. package/src/pages/Admin/Settings/DataRetention.vue +182 -0
  150. package/src/pages/Admin/Settings/EmailSettings.vue +243 -0
  151. package/src/pages/Admin/Settings/Sandbox.vue +135 -0
  152. package/src/pages/Admin/Settings/SsoSettings.vue +218 -0
  153. package/src/pages/Admin/Settings/TwoFactor.vue +110 -0
  154. package/src/pages/Admin/Settings.vue +847 -99
  155. package/src/pages/Admin/Skills/Form.vue +53 -0
  156. package/src/pages/Admin/Skills/Index.vue +94 -0
  157. package/src/pages/Admin/SlaPolicies/Form.vue +62 -19
  158. package/src/pages/Admin/SlaPolicies/Index.vue +85 -23
  159. package/src/pages/Admin/Statuses/Form.vue +114 -0
  160. package/src/pages/Admin/Statuses/Index.vue +153 -0
  161. package/src/pages/Admin/Tags/Index.vue +121 -35
  162. package/src/pages/Admin/Tickets/Index.vue +96 -9
  163. package/src/pages/Admin/Tickets/Show.vue +130 -37
  164. package/src/pages/Admin/Webhooks/DeliveryLog.vue +120 -0
  165. package/src/pages/Admin/Webhooks/Form.vue +110 -0
  166. package/src/pages/Admin/Webhooks/Index.vue +136 -0
  167. package/src/pages/Admin/Workflows/Builder.vue +207 -0
  168. package/src/pages/Admin/Workflows/Index.vue +235 -0
  169. package/src/pages/Admin/Workflows/Logs.vue +286 -0
  170. package/src/pages/Agent/Dashboard.vue +311 -186
  171. package/src/pages/Agent/TicketIndex.vue +80 -6
  172. package/src/pages/Agent/TicketShow.vue +399 -60
  173. package/src/pages/Customer/Create.vue +37 -10
  174. package/src/pages/Customer/Index.vue +9 -2
  175. package/src/pages/Customer/KnowledgeBase/Article.vue +129 -0
  176. package/src/pages/Customer/KnowledgeBase/Index.vue +151 -0
  177. package/src/pages/Customer/Show.vue +69 -63
  178. package/src/pages/Guest/Create.vue +40 -15
  179. package/src/pages/Guest/Show.vue +124 -93
  180. package/src/plugin.js +111 -1
  181. package/src/utils/constants.js +30 -0
  182. package/src/utils/formatting.js +35 -0
  183. package/src/utils/mentionHighlight.js +24 -0
  184. package/src/utils/sanitizeHtml.js +78 -64
  185. package/src/widget/EscalatedWidget.vue +804 -0
  186. package/src/widget/index.js +254 -0
  187. package/src/pages/Admin/Plugins.vue +0 -129
@@ -0,0 +1,134 @@
1
+ import { ref, onUnmounted } from 'vue';
2
+
3
+ /**
4
+ * Composable that detects `@` typed in a text input/textarea,
5
+ * fetches agent suggestions from the API (debounced), and provides
6
+ * an insert function to replace the mention token.
7
+ *
8
+ * @param {Object} options
9
+ * @param {string} [options.searchEndpoint] - API endpoint for agent search (default: route-based)
10
+ * @param {number} [options.debounce=250] - Debounce delay in ms
11
+ * @returns {Object}
12
+ */
13
+ export function useMentions(options = {}) {
14
+ const { debounce = 250 } = options;
15
+
16
+ const suggestions = ref([]);
17
+ const isActive = ref(false);
18
+ const query = ref('');
19
+ const mentionStart = ref(null); // cursor position where `@` was typed
20
+ const loading = ref(false);
21
+
22
+ let timer = null;
23
+
24
+ function clearTimer() {
25
+ if (timer !== null) {
26
+ window.clearTimeout(timer);
27
+ timer = null;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Call this on every input/keyup event with the textarea element
33
+ * and the current text value.
34
+ */
35
+ function onTextChange(textareaEl, text) {
36
+ if (!textareaEl) return;
37
+
38
+ const cursorPos = textareaEl.selectionStart;
39
+ const textBeforeCursor = text.slice(0, cursorPos);
40
+
41
+ // Find the last `@` that starts a mention (preceded by whitespace or start of string)
42
+ const mentionMatch = textBeforeCursor.match(/(?:^|[\s(])@([a-zA-Z0-9_ ]*)$/);
43
+
44
+ if (mentionMatch) {
45
+ const searchQuery = mentionMatch[1];
46
+ // The @ is at cursorPos minus the matched group minus 1 for the @
47
+ mentionStart.value = cursorPos - searchQuery.length - 1;
48
+ query.value = searchQuery;
49
+ isActive.value = true;
50
+ debouncedFetch(searchQuery);
51
+ } else {
52
+ close();
53
+ }
54
+ }
55
+
56
+ function debouncedFetch(searchQuery) {
57
+ clearTimer();
58
+
59
+ if (searchQuery.length < 1) {
60
+ fetchSuggestions('');
61
+ return;
62
+ }
63
+
64
+ timer = window.setTimeout(() => {
65
+ fetchSuggestions(searchQuery);
66
+ }, debounce);
67
+ }
68
+
69
+ async function fetchSuggestions(searchQuery) {
70
+ loading.value = true;
71
+ try {
72
+ const endpoint = options.searchEndpoint || '/support/admin/agents/search';
73
+ const url = `${endpoint}?q=${encodeURIComponent(searchQuery)}`;
74
+ const response = await fetch(url, {
75
+ headers: {
76
+ Accept: 'application/json',
77
+ 'X-Requested-With': 'XMLHttpRequest',
78
+ 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content || '',
79
+ },
80
+ });
81
+ if (response.ok) {
82
+ suggestions.value = await response.json();
83
+ } else {
84
+ suggestions.value = [];
85
+ }
86
+ } catch {
87
+ suggestions.value = [];
88
+ } finally {
89
+ loading.value = false;
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Insert the selected agent mention into the text.
95
+ * Returns the new text value with the mention inserted.
96
+ *
97
+ * @param {string} currentText - Current textarea value
98
+ * @param {Object} agent - Agent object with `name` property
99
+ * @returns {string} Updated text
100
+ */
101
+ function insertMention(currentText, agent) {
102
+ if (mentionStart.value === null) return currentText;
103
+
104
+ const before = currentText.slice(0, mentionStart.value);
105
+ const cursorPos = mentionStart.value + 1 + query.value.length;
106
+ const after = currentText.slice(cursorPos);
107
+
108
+ const mentionText = `@{${agent.name}} `;
109
+ const newText = before + mentionText + after;
110
+
111
+ close();
112
+ return newText;
113
+ }
114
+
115
+ function close() {
116
+ isActive.value = false;
117
+ suggestions.value = [];
118
+ query.value = '';
119
+ mentionStart.value = null;
120
+ clearTimer();
121
+ }
122
+
123
+ onUnmounted(clearTimer);
124
+
125
+ return {
126
+ suggestions,
127
+ isActive,
128
+ query,
129
+ loading,
130
+ onTextChange,
131
+ insertMention,
132
+ close,
133
+ };
134
+ }
@@ -1,67 +1,159 @@
1
- import { computed } from 'vue';
2
- import { usePage } from '@inertiajs/vue3';
3
-
4
- /**
5
- * Composable for reading plugin extensions from Inertia shared props.
6
- *
7
- * The Laravel backend (escalated-laravel) shares plugin UI extensions via
8
- * `$page.props.escalated.plugins`, which contains:
9
- * - menuItems: Array of navigation items injected by plugins
10
- * - dashboardWidgets: Array of widget definitions for the agent dashboard
11
- * - pageComponents: Object mapping slot names to arrays of component definitions
12
- *
13
- * @returns {Object} Plugin extension data and helper functions
14
- */
15
- export function usePluginExtensions() {
16
- const page = usePage();
17
-
18
- const pluginData = computed(() => page.props?.escalated?.plugins || {});
19
-
20
- /**
21
- * Menu items injected by plugins, sorted by position.
22
- * Each item: { label, route, icon, position, permission, badge, submenu }
23
- */
24
- const menuItems = computed(() => {
25
- const items = pluginData.value.menuItems || [];
26
- return [...items].sort((a, b) => (a.position || 100) - (b.position || 100));
27
- });
28
-
29
- /**
30
- * Dashboard widgets injected by plugins, sorted by position.
31
- * Each widget: { id, title, component, plugin, data, position, width }
32
- */
33
- const dashboardWidgets = computed(() => {
34
- const widgets = pluginData.value.dashboardWidgets || [];
35
- return [...widgets].sort((a, b) => (a.position || 100) - (b.position || 100));
36
- });
37
-
38
- /**
39
- * Get plugin components for a specific page slot, sorted by position.
40
- *
41
- * @param {string} pageName - The page name (e.g. 'dashboard', 'ticket.show')
42
- * @param {string} slotName - The slot name (e.g. 'header', 'sidebar', 'footer')
43
- * @returns {Array} Sorted array of component definitions for the given slot
44
- */
45
- function getPageComponents(pageName, slotName) {
46
- const key = `${pageName}.${slotName}`;
47
- const components = pluginData.value.pageComponents || {};
48
- return [...(components[key] || [])].sort((a, b) => (a.position || 100) - (b.position || 100));
49
- }
50
-
51
- /**
52
- * Check whether any plugins have registered extensions.
53
- */
54
- const hasPlugins = computed(() => {
55
- return menuItems.value.length > 0
56
- || dashboardWidgets.value.length > 0
57
- || Object.keys(pluginData.value.pageComponents || {}).length > 0;
58
- });
59
-
60
- return {
61
- pluginData,
62
- menuItems,
63
- dashboardWidgets,
64
- getPageComponents,
65
- hasPlugins,
66
- };
67
- }
1
+ import { computed } from 'vue';
2
+ import { usePage } from '@inertiajs/vue3';
3
+
4
+ /**
5
+ * Composable for reading plugin extensions from Inertia shared props.
6
+ *
7
+ * The Laravel backend (escalated-laravel) shares plugin UI extensions via
8
+ * `$page.props.escalated.plugins`, which contains:
9
+ * - menuItems: Array of navigation items injected by plugins
10
+ * - dashboardWidgets: Array of widget definitions for the agent dashboard
11
+ * - pageComponents: Object mapping slot names to arrays of component definitions
12
+ *
13
+ * @returns {Object} Plugin extension data and helper functions
14
+ */
15
+ export function usePluginExtensions() {
16
+ const page = usePage();
17
+
18
+ const pluginData = computed(() => page.props?.escalated?.plugins || {});
19
+
20
+ /**
21
+ * Menu items injected by plugins, sorted by position.
22
+ * Each item: { label, route, icon, position, permission, badge, submenu }
23
+ */
24
+ const menuItems = computed(() => {
25
+ const items = pluginData.value.menuItems || [];
26
+ return [...items].sort((a, b) => (a.position || 100) - (b.position || 100));
27
+ });
28
+
29
+ /**
30
+ * Dashboard widgets injected by plugins, sorted by position.
31
+ * Each widget: { id, title, component, plugin, data, position, width }
32
+ */
33
+ const dashboardWidgets = computed(() => {
34
+ const widgets = pluginData.value.dashboardWidgets || [];
35
+ return [...widgets].sort((a, b) => (a.position || 100) - (b.position || 100));
36
+ });
37
+
38
+ /**
39
+ * Ticket actions injected by plugins (e.g., "Escalate to Jira", "Send Approval").
40
+ * Each action: { id, label, icon, handler, position, permission, context }
41
+ * context: 'agent' | 'admin' | 'both'
42
+ */
43
+ const ticketActions = computed(() => {
44
+ const actions = pluginData.value.ticketActions || [];
45
+ return [...actions].sort((a, b) => (a.position || 100) - (b.position || 100));
46
+ });
47
+
48
+ /**
49
+ * Sidebar panels injected by plugins for the ticket detail context panel.
50
+ * Each panel: { id, title, component, plugin, position, collapsed, icon }
51
+ */
52
+ const sidebarPanels = computed(() => {
53
+ const panels = pluginData.value.sidebarPanels || [];
54
+ return [...panels].sort((a, b) => (a.position || 100) - (b.position || 100));
55
+ });
56
+
57
+ /**
58
+ * Custom ticket fields injected by plugins for ticket creation/edit forms.
59
+ * Each field: { id, label, type, name, options, required, position, plugin }
60
+ * type: 'text' | 'textarea' | 'select' | 'checkbox' | 'date' | 'number'
61
+ */
62
+ const ticketFields = computed(() => {
63
+ const fields = pluginData.value.ticketFields || [];
64
+ return [...fields].sort((a, b) => (a.position || 100) - (b.position || 100));
65
+ });
66
+
67
+ /**
68
+ * Reply composer actions injected by plugins (e.g., "AI Suggest", "Insert KB Article").
69
+ * Each action: { id, label, icon, handler, component, plugin, position }
70
+ */
71
+ const composerActions = computed(() => {
72
+ const actions = pluginData.value.composerActions || [];
73
+ return [...actions].sort((a, b) => (a.position || 100) - (b.position || 100));
74
+ });
75
+
76
+ /**
77
+ * Report widgets injected by plugins for the admin reports page.
78
+ * Each widget: { id, title, component, plugin, data, position, width }
79
+ */
80
+ const reportWidgets = computed(() => {
81
+ const widgets = pluginData.value.reportWidgets || [];
82
+ return [...widgets].sort((a, b) => (a.position || 100) - (b.position || 100));
83
+ });
84
+
85
+ /**
86
+ * Settings panels injected by plugins for the admin settings page.
87
+ * Each panel: { id, title, component, plugin, position, icon }
88
+ */
89
+ const settingsPanels = computed(() => {
90
+ const panels = pluginData.value.settingsPanels || [];
91
+ return [...panels].sort((a, b) => (a.position || 100) - (b.position || 100));
92
+ });
93
+
94
+ /**
95
+ * Notification channels registered by plugins (e.g., Slack, SMS, WhatsApp).
96
+ * Each channel: { id, label, icon, plugin, configComponent }
97
+ */
98
+ const notificationChannels = computed(() => {
99
+ const channels = pluginData.value.notificationChannels || [];
100
+ return [...channels].sort((a, b) => (a.position || 100) - (b.position || 100));
101
+ });
102
+
103
+ /**
104
+ * Custom ticket list columns injected by plugins.
105
+ * Each column: { id, label, key, component, plugin, position, width }
106
+ */
107
+ const ticketListColumns = computed(() => {
108
+ const columns = pluginData.value.ticketListColumns || [];
109
+ return [...columns].sort((a, b) => (a.position || 100) - (b.position || 100));
110
+ });
111
+
112
+ /**
113
+ * Get plugin components for a specific page slot, sorted by position.
114
+ *
115
+ * @param {string} pageName - The page name (e.g. 'dashboard', 'ticket.show')
116
+ * @param {string} slotName - The slot name (e.g. 'header', 'sidebar', 'footer')
117
+ * @returns {Array} Sorted array of component definitions for the given slot
118
+ */
119
+ function getPageComponents(pageName, slotName) {
120
+ const key = `${pageName}.${slotName}`;
121
+ const components = pluginData.value.pageComponents || {};
122
+ return [...(components[key] || [])].sort((a, b) => (a.position || 100) - (b.position || 100));
123
+ }
124
+
125
+ /**
126
+ * Check whether any plugins have registered extensions.
127
+ */
128
+ const hasPlugins = computed(() => {
129
+ return (
130
+ menuItems.value.length > 0 ||
131
+ dashboardWidgets.value.length > 0 ||
132
+ Object.keys(pluginData.value.pageComponents || {}).length > 0 ||
133
+ ticketActions.value.length > 0 ||
134
+ sidebarPanels.value.length > 0 ||
135
+ ticketFields.value.length > 0 ||
136
+ composerActions.value.length > 0 ||
137
+ reportWidgets.value.length > 0 ||
138
+ settingsPanels.value.length > 0 ||
139
+ notificationChannels.value.length > 0 ||
140
+ ticketListColumns.value.length > 0
141
+ );
142
+ });
143
+
144
+ return {
145
+ pluginData,
146
+ menuItems,
147
+ dashboardWidgets,
148
+ ticketActions,
149
+ sidebarPanels,
150
+ ticketFields,
151
+ composerActions,
152
+ reportWidgets,
153
+ settingsPanels,
154
+ notificationChannels,
155
+ ticketListColumns,
156
+ getPageComponents,
157
+ hasPlugins,
158
+ };
159
+ }
@@ -0,0 +1,65 @@
1
+ import { getCurrentInstance } from 'vue';
2
+
3
+ /**
4
+ * Composable for dispatching and consuming plugin hooks.
5
+ *
6
+ * Hooks allow plugins to react to events (e.g., ticket.created, ticket.replied)
7
+ * and to filter/modify data before it's processed (e.g., reply.beforeSubmit).
8
+ *
9
+ * Action hooks: fire-and-forget, all handlers run
10
+ * Filter hooks: chain handlers, each can modify the value
11
+ *
12
+ * @returns {Object} Hook dispatch functions
13
+ */
14
+ export function usePluginHooks() {
15
+ const instance = getCurrentInstance();
16
+ const hookRegistry = instance?.appContext?.config?.globalProperties?.$escalatedHooks || {};
17
+
18
+ /**
19
+ * Dispatch an action hook. All registered handlers are called.
20
+ * @param {string} event - Hook name (e.g., 'ticket.created')
21
+ * @param {...any} args - Arguments passed to handlers
22
+ */
23
+ async function dispatch(event, ...args) {
24
+ const handlers = hookRegistry[event] || [];
25
+ for (const { handler } of handlers) {
26
+ try {
27
+ await handler(...args);
28
+ } catch (err) {
29
+ console.warn(`[Escalated] Plugin hook "${event}" error:`, err);
30
+ }
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Dispatch a filter hook. Each handler receives the value and can return a modified version.
36
+ * @param {string} event - Hook name (e.g., 'reply.beforeSubmit')
37
+ * @param {*} value - The value to filter
38
+ * @param {...any} args - Additional arguments passed to handlers
39
+ * @returns {*} The filtered value
40
+ */
41
+ async function filter(event, value, ...args) {
42
+ const handlers = hookRegistry[event] || [];
43
+ let result = value;
44
+ for (const { handler } of handlers) {
45
+ try {
46
+ const modified = await handler(result, ...args);
47
+ if (modified !== undefined) result = modified;
48
+ } catch (err) {
49
+ console.warn(`[Escalated] Plugin filter "${event}" error:`, err);
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+
55
+ /**
56
+ * Check if any handlers are registered for a given hook.
57
+ * @param {string} event - Hook name
58
+ * @returns {boolean}
59
+ */
60
+ function hasHook(event) {
61
+ return (hookRegistry[event] || []).length > 0;
62
+ }
63
+
64
+ return { dispatch, filter, hasHook };
65
+ }
@@ -0,0 +1,182 @@
1
+ import { ref, onUnmounted, readonly } from 'vue';
2
+
3
+ /**
4
+ * Composable for real-time WebSocket event listening via Laravel Echo.
5
+ *
6
+ * If `window.Echo` is available (provided by the host app), this composable
7
+ * subscribes to private channels and listens for broadcast events. When Echo
8
+ * is not present, it silently falls back - the caller can check `echoAvailable`
9
+ * and implement polling as needed.
10
+ *
11
+ * Usage:
12
+ * const { echoAvailable, subscribeToTicket, subscribeToTickets, subscribeToAgent } = useRealtime();
13
+ *
14
+ * All subscriptions are automatically cleaned up on component unmount.
15
+ */
16
+ export function useRealtime() {
17
+ const echoAvailable = ref(typeof window !== 'undefined' && !!window.Echo);
18
+ const subscriptions = [];
19
+
20
+ /**
21
+ * Subscribe to a private channel and listen for an event.
22
+ * Returns an unsubscribe function.
23
+ */
24
+ function listen(channelName, eventName, callback) {
25
+ if (!echoAvailable.value) return () => {};
26
+
27
+ const channel = window.Echo.private(channelName);
28
+ channel.listen(eventName, callback);
29
+
30
+ const unsub = () => {
31
+ channel.stopListening(eventName, callback);
32
+ window.Echo.leave(channelName);
33
+ };
34
+ subscriptions.push(unsub);
35
+ return unsub;
36
+ }
37
+
38
+ /**
39
+ * Subscribe to a specific ticket's channel for real-time updates.
40
+ *
41
+ * @param {number|string} ticketId - The ticket ID
42
+ * @param {Object} handlers - Event handler callbacks
43
+ * @param {Function} [handlers.onReplyCreated] - Called when a new reply is added
44
+ * @param {Function} [handlers.onTicketUpdated] - Called when ticket fields are updated
45
+ * @param {Function} [handlers.onStatusChanged] - Called when ticket status changes
46
+ * @param {Function} [handlers.onTicketAssigned] - Called when ticket is assigned
47
+ * @param {Function} [handlers.onTicketEscalated] - Called when ticket is escalated
48
+ * @returns {Function} Unsubscribe function
49
+ */
50
+ function subscribeToTicket(ticketId, handlers = {}) {
51
+ if (!echoAvailable.value) return () => {};
52
+
53
+ const channelName = `escalated.tickets.${ticketId}`;
54
+ const channel = window.Echo.private(channelName);
55
+ const listeners = [];
56
+
57
+ if (handlers.onReplyCreated) {
58
+ channel.listen('.reply.created', handlers.onReplyCreated);
59
+ listeners.push(['.reply.created', handlers.onReplyCreated]);
60
+ }
61
+ if (handlers.onTicketUpdated) {
62
+ channel.listen('.ticket.updated', handlers.onTicketUpdated);
63
+ listeners.push(['.ticket.updated', handlers.onTicketUpdated]);
64
+ }
65
+ if (handlers.onStatusChanged) {
66
+ channel.listen('.ticket.status_changed', handlers.onStatusChanged);
67
+ listeners.push(['.ticket.status_changed', handlers.onStatusChanged]);
68
+ }
69
+ if (handlers.onTicketAssigned) {
70
+ channel.listen('.ticket.assigned', handlers.onTicketAssigned);
71
+ listeners.push(['.ticket.assigned', handlers.onTicketAssigned]);
72
+ }
73
+ if (handlers.onTicketEscalated) {
74
+ channel.listen('.ticket.escalated', handlers.onTicketEscalated);
75
+ listeners.push(['.ticket.escalated', handlers.onTicketEscalated]);
76
+ }
77
+
78
+ const unsub = () => {
79
+ listeners.forEach(([event, cb]) => channel.stopListening(event, cb));
80
+ window.Echo.leave(channelName);
81
+ };
82
+ subscriptions.push(unsub);
83
+ return unsub;
84
+ }
85
+
86
+ /**
87
+ * Subscribe to the global tickets channel for new ticket notifications.
88
+ *
89
+ * @param {Object} handlers - Event handler callbacks
90
+ * @param {Function} [handlers.onTicketCreated] - Called when a new ticket is created
91
+ * @returns {Function} Unsubscribe function
92
+ */
93
+ function subscribeToTickets(handlers = {}) {
94
+ if (!echoAvailable.value) return () => {};
95
+
96
+ const channelName = 'escalated.tickets';
97
+ const channel = window.Echo.private(channelName);
98
+ const listeners = [];
99
+
100
+ if (handlers.onTicketCreated) {
101
+ channel.listen('.ticket.created', handlers.onTicketCreated);
102
+ listeners.push(['.ticket.created', handlers.onTicketCreated]);
103
+ }
104
+
105
+ const unsub = () => {
106
+ listeners.forEach(([event, cb]) => channel.stopListening(event, cb));
107
+ window.Echo.leave(channelName);
108
+ };
109
+ subscriptions.push(unsub);
110
+ return unsub;
111
+ }
112
+
113
+ /**
114
+ * Subscribe to an agent's personal channel for assignment notifications.
115
+ *
116
+ * @param {number|string} agentId - The agent's user ID
117
+ * @param {Object} handlers - Event handler callbacks
118
+ * @param {Function} [handlers.onTicketAssigned] - Called when a ticket is assigned to this agent
119
+ * @returns {Function} Unsubscribe function
120
+ */
121
+ function subscribeToAgent(agentId, handlers = {}) {
122
+ if (!echoAvailable.value) return () => {};
123
+
124
+ const channelName = `escalated.agents.${agentId}`;
125
+ const channel = window.Echo.private(channelName);
126
+ const listeners = [];
127
+
128
+ if (handlers.onTicketAssigned) {
129
+ channel.listen('.ticket.assigned', handlers.onTicketAssigned);
130
+ listeners.push(['.ticket.assigned', handlers.onTicketAssigned]);
131
+ }
132
+
133
+ const unsub = () => {
134
+ listeners.forEach(([event, cb]) => channel.stopListening(event, cb));
135
+ window.Echo.leave(channelName);
136
+ };
137
+ subscriptions.push(unsub);
138
+ return unsub;
139
+ }
140
+
141
+ /**
142
+ * Get a presence channel for a ticket (if Echo supports it).
143
+ * Returns the channel instance or null.
144
+ */
145
+ function joinTicketPresence(ticketId, callbacks = {}) {
146
+ if (!echoAvailable.value) return null;
147
+
148
+ const channelName = `escalated.tickets.${ticketId}`;
149
+ const channel = window.Echo.join(channelName);
150
+
151
+ if (callbacks.here) channel.here(callbacks.here);
152
+ if (callbacks.joining) channel.joining(callbacks.joining);
153
+ if (callbacks.leaving) channel.leaving(callbacks.leaving);
154
+
155
+ const unsub = () => {
156
+ window.Echo.leave(`presence-${channelName}`);
157
+ };
158
+ subscriptions.push(unsub);
159
+ return { channel, unsubscribe: unsub };
160
+ }
161
+
162
+ // Cleanup all subscriptions on component unmount
163
+ onUnmounted(() => {
164
+ subscriptions.forEach((unsub) => {
165
+ try {
166
+ unsub();
167
+ } catch {
168
+ /* ignore */
169
+ }
170
+ });
171
+ subscriptions.length = 0;
172
+ });
173
+
174
+ return {
175
+ echoAvailable: readonly(echoAvailable),
176
+ listen,
177
+ subscribeToTicket,
178
+ subscribeToTickets,
179
+ subscribeToAgent,
180
+ joinTicketPresence,
181
+ };
182
+ }