@consilioweb/payload-support 0.5.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 (189) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +525 -0
  3. package/dist/client.cjs +7 -0
  4. package/dist/client.d.cts +3 -0
  5. package/dist/client.d.ts +3 -0
  6. package/dist/client.js +5 -0
  7. package/dist/index.cjs +7766 -0
  8. package/dist/index.d.cts +384 -0
  9. package/dist/index.d.ts +384 -0
  10. package/dist/index.js +7730 -0
  11. package/dist/views.d.cts +30 -0
  12. package/dist/views.d.ts +30 -0
  13. package/package.json +131 -0
  14. package/src/client.ts +1 -0
  15. package/src/collections/AuthLogs.ts +65 -0
  16. package/src/collections/CannedResponses.ts +69 -0
  17. package/src/collections/ChatMessages.ts +98 -0
  18. package/src/collections/EmailLogs.ts +94 -0
  19. package/src/collections/KnowledgeBase.ts +99 -0
  20. package/src/collections/Macros.ts +98 -0
  21. package/src/collections/PendingEmails.ts +122 -0
  22. package/src/collections/SatisfactionSurveys.ts +98 -0
  23. package/src/collections/SlaPolicies.ts +123 -0
  24. package/src/collections/SupportClients.ts +210 -0
  25. package/src/collections/TicketActivityLog.ts +81 -0
  26. package/src/collections/TicketMessages.ts +364 -0
  27. package/src/collections/TicketStatuses.ts +108 -0
  28. package/src/collections/Tickets.ts +704 -0
  29. package/src/collections/TimeEntries.ts +105 -0
  30. package/src/collections/WebhookEndpoints.ts +96 -0
  31. package/src/collections/index.ts +16 -0
  32. package/src/components/TicketConversation/components/AISummaryPanel.tsx +85 -0
  33. package/src/components/TicketConversation/components/ActionPanels.tsx +140 -0
  34. package/src/components/TicketConversation/components/ActivityLog.tsx +39 -0
  35. package/src/components/TicketConversation/components/ClientBar.tsx +37 -0
  36. package/src/components/TicketConversation/components/ClientHistory.tsx +117 -0
  37. package/src/components/TicketConversation/components/CodeBlock.tsx +186 -0
  38. package/src/components/TicketConversation/components/CodeBlockInserter.tsx +166 -0
  39. package/src/components/TicketConversation/components/QuickActions.tsx +82 -0
  40. package/src/components/TicketConversation/components/TicketHeader.tsx +91 -0
  41. package/src/components/TicketConversation/components/TimeTrackingPanel.tsx +161 -0
  42. package/src/components/TicketConversation/config.ts +82 -0
  43. package/src/components/TicketConversation/constants.ts +74 -0
  44. package/src/components/TicketConversation/context.ts +63 -0
  45. package/src/components/TicketConversation/hooks/useAI.ts +180 -0
  46. package/src/components/TicketConversation/hooks/useMessageActions.ts +131 -0
  47. package/src/components/TicketConversation/hooks/useReply.ts +190 -0
  48. package/src/components/TicketConversation/hooks/useTicketActions.ts +205 -0
  49. package/src/components/TicketConversation/hooks/useTimeTracking.ts +107 -0
  50. package/src/components/TicketConversation/hooks/useTranslation.ts +116 -0
  51. package/src/components/TicketConversation/index.tsx +1110 -0
  52. package/src/components/TicketConversation/locales/en.json +878 -0
  53. package/src/components/TicketConversation/locales/fr.json +878 -0
  54. package/src/components/TicketConversation/types.ts +54 -0
  55. package/src/components/TicketConversation/utils.ts +25 -0
  56. package/src/endpoints/admin-chat-stream.ts +238 -0
  57. package/src/endpoints/admin-chat.ts +263 -0
  58. package/src/endpoints/admin-stats.ts +200 -0
  59. package/src/endpoints/ai.ts +199 -0
  60. package/src/endpoints/apply-macro.ts +144 -0
  61. package/src/endpoints/auth-2fa.ts +163 -0
  62. package/src/endpoints/auto-close.ts +175 -0
  63. package/src/endpoints/billing.ts +167 -0
  64. package/src/endpoints/bulk-action.ts +103 -0
  65. package/src/endpoints/chat-stream.ts +127 -0
  66. package/src/endpoints/chat.ts +188 -0
  67. package/src/endpoints/chatbot.ts +113 -0
  68. package/src/endpoints/delete-account.ts +129 -0
  69. package/src/endpoints/email-stats.ts +109 -0
  70. package/src/endpoints/export-csv.ts +84 -0
  71. package/src/endpoints/export-data.ts +104 -0
  72. package/src/endpoints/import-conversation.ts +307 -0
  73. package/src/endpoints/index.ts +154 -0
  74. package/src/endpoints/login.ts +92 -0
  75. package/src/endpoints/merge-clients.ts +132 -0
  76. package/src/endpoints/merge-tickets.ts +137 -0
  77. package/src/endpoints/oauth-google.ts +179 -0
  78. package/src/endpoints/pending-emails-process.ts +224 -0
  79. package/src/endpoints/presence.ts +104 -0
  80. package/src/endpoints/process-scheduled.ts +144 -0
  81. package/src/endpoints/purge-logs.ts +58 -0
  82. package/src/endpoints/resend-notification.ts +99 -0
  83. package/src/endpoints/round-robin-config.ts +92 -0
  84. package/src/endpoints/satisfaction.ts +93 -0
  85. package/src/endpoints/search.ts +106 -0
  86. package/src/endpoints/seed-kb.ts +153 -0
  87. package/src/endpoints/settings.ts +144 -0
  88. package/src/endpoints/signature.ts +93 -0
  89. package/src/endpoints/sla-check.ts +124 -0
  90. package/src/endpoints/split-ticket.ts +131 -0
  91. package/src/endpoints/statuses.ts +45 -0
  92. package/src/endpoints/track-open.ts +154 -0
  93. package/src/endpoints/typing.ts +101 -0
  94. package/src/endpoints/user-prefs.ts +125 -0
  95. package/src/hooks/checkSLA.ts +414 -0
  96. package/src/hooks/ticketStatusEmail.ts +182 -0
  97. package/src/index.ts +51 -0
  98. package/src/plugin.ts +157 -0
  99. package/src/portal/LiveChat.tsx +1353 -0
  100. package/src/portal/auth/ChatWidget.tsx +350 -0
  101. package/src/portal/auth/ChatbotWidget.tsx +285 -0
  102. package/src/portal/auth/SupportHeader.tsx +409 -0
  103. package/src/portal/auth/dashboard/DashboardClient.tsx +650 -0
  104. package/src/portal/auth/dashboard/page.tsx +84 -0
  105. package/src/portal/auth/faq/FAQSearch.tsx +117 -0
  106. package/src/portal/auth/faq/page.tsx +199 -0
  107. package/src/portal/auth/layout.tsx +61 -0
  108. package/src/portal/auth/profile/page.tsx +705 -0
  109. package/src/portal/auth/tickets/detail/CloseTicketButton.tsx +74 -0
  110. package/src/portal/auth/tickets/detail/CollapsibleMessages.tsx +46 -0
  111. package/src/portal/auth/tickets/detail/MarkSolutionButton.tsx +50 -0
  112. package/src/portal/auth/tickets/detail/MessageActions.tsx +158 -0
  113. package/src/portal/auth/tickets/detail/PrintButton.tsx +16 -0
  114. package/src/portal/auth/tickets/detail/ReadReceipt.tsx +34 -0
  115. package/src/portal/auth/tickets/detail/ReopenTicketButton.tsx +74 -0
  116. package/src/portal/auth/tickets/detail/SatisfactionForm.tsx +156 -0
  117. package/src/portal/auth/tickets/detail/TicketPolling.tsx +57 -0
  118. package/src/portal/auth/tickets/detail/TicketReplyForm.tsx +294 -0
  119. package/src/portal/auth/tickets/detail/TypingIndicator.tsx +58 -0
  120. package/src/portal/auth/tickets/detail/page.tsx +738 -0
  121. package/src/portal/auth/tickets/new/page.tsx +515 -0
  122. package/src/portal/forgot-password/page.tsx +114 -0
  123. package/src/portal/layout.tsx +26 -0
  124. package/src/portal/locales/en.json +374 -0
  125. package/src/portal/locales/fr.json +374 -0
  126. package/src/portal/login/page.tsx +351 -0
  127. package/src/portal/page.tsx +162 -0
  128. package/src/portal/register/page.tsx +281 -0
  129. package/src/portal/reset-password/page.tsx +152 -0
  130. package/src/styles/BillingView.module.scss +311 -0
  131. package/src/styles/ChatView.module.scss +438 -0
  132. package/src/styles/CommandPalette.module.scss +160 -0
  133. package/src/styles/CrmView.module.scss +554 -0
  134. package/src/styles/EmailTracking.module.scss +238 -0
  135. package/src/styles/ImportConversation.module.scss +267 -0
  136. package/src/styles/Layout.module.scss +55 -0
  137. package/src/styles/Logs.module.scss +164 -0
  138. package/src/styles/NewTicket.module.scss +143 -0
  139. package/src/styles/PendingEmails.module.scss +629 -0
  140. package/src/styles/SupportDashboard.module.scss +649 -0
  141. package/src/styles/TicketDetail.module.scss +1043 -0
  142. package/src/styles/TicketInbox.module.scss +296 -0
  143. package/src/styles/TicketingSettings.module.scss +358 -0
  144. package/src/styles/TimeDashboard.module.scss +287 -0
  145. package/src/styles/_tokens.scss +78 -0
  146. package/src/styles/theme.css +633 -0
  147. package/src/types.ts +255 -0
  148. package/src/utils/adminNotification.ts +38 -0
  149. package/src/utils/auth.ts +46 -0
  150. package/src/utils/emailTemplate.ts +343 -0
  151. package/src/utils/fireWebhooks.ts +84 -0
  152. package/src/utils/index.ts +22 -0
  153. package/src/utils/rateLimiter.ts +52 -0
  154. package/src/utils/readSettings.ts +67 -0
  155. package/src/utils/slugs.ts +54 -0
  156. package/src/utils/webhookDispatcher.ts +120 -0
  157. package/src/views/BillingView/client.tsx +137 -0
  158. package/src/views/BillingView/index.tsx +33 -0
  159. package/src/views/ChatView/client.tsx +294 -0
  160. package/src/views/ChatView/index.tsx +33 -0
  161. package/src/views/CrmView/client.tsx +206 -0
  162. package/src/views/CrmView/index.tsx +33 -0
  163. package/src/views/EmailTrackingView/client.tsx +124 -0
  164. package/src/views/EmailTrackingView/index.tsx +33 -0
  165. package/src/views/ImportConversationView/client.tsx +133 -0
  166. package/src/views/ImportConversationView/index.tsx +33 -0
  167. package/src/views/LogsView/client.tsx +151 -0
  168. package/src/views/LogsView/index.tsx +30 -0
  169. package/src/views/NewTicketView/client.tsx +227 -0
  170. package/src/views/NewTicketView/index.tsx +30 -0
  171. package/src/views/PendingEmailsView/client.tsx +177 -0
  172. package/src/views/PendingEmailsView/index.tsx +33 -0
  173. package/src/views/SupportDashboardView/client.tsx +424 -0
  174. package/src/views/SupportDashboardView/index.tsx +33 -0
  175. package/src/views/TicketDetailView/client.tsx +775 -0
  176. package/src/views/TicketDetailView/index.tsx +33 -0
  177. package/src/views/TicketInboxView/client.tsx +313 -0
  178. package/src/views/TicketInboxView/index.tsx +30 -0
  179. package/src/views/TicketingSettingsView/client.tsx +866 -0
  180. package/src/views/TicketingSettingsView/index.tsx +33 -0
  181. package/src/views/TimeDashboardView/client.tsx +144 -0
  182. package/src/views/TimeDashboardView/index.tsx +33 -0
  183. package/src/views/shared/AdminViewHeader.tsx +69 -0
  184. package/src/views/shared/ErrorBoundary.tsx +68 -0
  185. package/src/views/shared/Skeleton.tsx +125 -0
  186. package/src/views/shared/adminTokens.ts +37 -0
  187. package/src/views/shared/config.ts +82 -0
  188. package/src/views/shared/index.ts +6 -0
  189. package/src/views.ts +16 -0
@@ -0,0 +1,30 @@
1
+ import { AdminViewServerProps } from 'payload';
2
+ import React from 'react';
3
+
4
+ declare const TicketInboxView: React.FC<AdminViewServerProps>;
5
+
6
+ declare const TicketDetailView: React.FC<AdminViewServerProps>;
7
+
8
+ declare const SupportDashboardView: React.FC<AdminViewServerProps>;
9
+
10
+ declare const NewTicketView: React.FC<AdminViewServerProps>;
11
+
12
+ declare const TicketingSettingsView: React.FC<AdminViewServerProps>;
13
+
14
+ declare const LogsView: React.FC<AdminViewServerProps>;
15
+
16
+ declare const ChatView: React.FC<AdminViewServerProps>;
17
+
18
+ declare const CrmView: React.FC<AdminViewServerProps>;
19
+
20
+ declare const PendingEmailsView: React.FC<AdminViewServerProps>;
21
+
22
+ declare const EmailTrackingView: React.FC<AdminViewServerProps>;
23
+
24
+ declare const BillingView: React.FC<AdminViewServerProps>;
25
+
26
+ declare const TimeDashboardView: React.FC<AdminViewServerProps>;
27
+
28
+ declare const ImportConversationView: React.FC<AdminViewServerProps>;
29
+
30
+ export { BillingView, ChatView, CrmView, EmailTrackingView, ImportConversationView, LogsView, NewTicketView, PendingEmailsView, SupportDashboardView, TicketDetailView, TicketInboxView, TicketingSettingsView, TimeDashboardView };
@@ -0,0 +1,30 @@
1
+ import { AdminViewServerProps } from 'payload';
2
+ import React from 'react';
3
+
4
+ declare const TicketInboxView: React.FC<AdminViewServerProps>;
5
+
6
+ declare const TicketDetailView: React.FC<AdminViewServerProps>;
7
+
8
+ declare const SupportDashboardView: React.FC<AdminViewServerProps>;
9
+
10
+ declare const NewTicketView: React.FC<AdminViewServerProps>;
11
+
12
+ declare const TicketingSettingsView: React.FC<AdminViewServerProps>;
13
+
14
+ declare const LogsView: React.FC<AdminViewServerProps>;
15
+
16
+ declare const ChatView: React.FC<AdminViewServerProps>;
17
+
18
+ declare const CrmView: React.FC<AdminViewServerProps>;
19
+
20
+ declare const PendingEmailsView: React.FC<AdminViewServerProps>;
21
+
22
+ declare const EmailTrackingView: React.FC<AdminViewServerProps>;
23
+
24
+ declare const BillingView: React.FC<AdminViewServerProps>;
25
+
26
+ declare const TimeDashboardView: React.FC<AdminViewServerProps>;
27
+
28
+ declare const ImportConversationView: React.FC<AdminViewServerProps>;
29
+
30
+ export { BillingView, ChatView, CrmView, EmailTrackingView, ImportConversationView, LogsView, NewTicketView, PendingEmailsView, SupportDashboardView, TicketDetailView, TicketInboxView, TicketingSettingsView, TimeDashboardView };
package/package.json ADDED
@@ -0,0 +1,131 @@
1
+ {
2
+ "name": "@consilioweb/payload-support",
3
+ "version": "0.5.1",
4
+ "description": "Payload CMS plugin — professional support & ticketing system with AI, SLA, time tracking, live chat, and more",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./client": {
21
+ "import": {
22
+ "types": "./dist/client.d.ts",
23
+ "default": "./dist/client.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/client.d.cts",
27
+ "default": "./dist/client.cjs"
28
+ }
29
+ },
30
+ "./views": {
31
+ "import": {
32
+ "types": "./dist/views.d.ts",
33
+ "default": "./dist/views.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/views.d.cts",
37
+ "default": "./dist/views.cjs"
38
+ }
39
+ },
40
+ "./src/views/*": "./src/views/*/index.tsx",
41
+ "./src/components/*": "./src/components/*/index.tsx"
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "src",
46
+ "README.md",
47
+ "LICENSE"
48
+ ],
49
+ "scripts": {
50
+ "build": "tsup",
51
+ "typecheck": "tsc --noEmit",
52
+ "prepublishOnly": "pnpm build"
53
+ },
54
+ "keywords": [
55
+ "payload",
56
+ "payload-cms",
57
+ "payload-plugin",
58
+ "support",
59
+ "ticketing",
60
+ "helpdesk",
61
+ "customer-support",
62
+ "sla",
63
+ "time-tracking",
64
+ "live-chat",
65
+ "ai",
66
+ "csat",
67
+ "knowledge-base",
68
+ "webhooks",
69
+ "email-tracking",
70
+ "canned-responses",
71
+ "macros",
72
+ "round-robin",
73
+ "crm",
74
+ "i18n",
75
+ "nextjs",
76
+ "react",
77
+ "typescript"
78
+ ],
79
+ "repository": {
80
+ "type": "git",
81
+ "url": "git+https://github.com/pOwn3d/payload-support.git"
82
+ },
83
+ "homepage": "https://github.com/pOwn3d/payload-support#readme",
84
+ "bugs": {
85
+ "url": "https://github.com/pOwn3d/payload-support/issues"
86
+ },
87
+ "author": "ConsilioWEB <contact@consilioweb.fr> (https://consilioweb.fr)",
88
+ "license": "MIT",
89
+ "peerDependencies": {
90
+ "@payloadcms/next": "^3.0.0",
91
+ "@payloadcms/translations": "^3.0.0",
92
+ "@payloadcms/ui": "^3.0.0",
93
+ "next": "^14.0.0 || ^15.0.0 || ^16.0.0",
94
+ "payload": "^3.0.0",
95
+ "react": "^18.0.0 || ^19.0.0",
96
+ "react-dom": "^18.0.0 || ^19.0.0"
97
+ },
98
+ "peerDependenciesMeta": {
99
+ "@payloadcms/ui": {
100
+ "optional": true
101
+ },
102
+ "@payloadcms/translations": {
103
+ "optional": true
104
+ },
105
+ "@payloadcms/next": {
106
+ "optional": true
107
+ },
108
+ "next": {
109
+ "optional": true
110
+ },
111
+ "react": {
112
+ "optional": true
113
+ },
114
+ "react-dom": {
115
+ "optional": true
116
+ }
117
+ },
118
+ "engines": {
119
+ "node": ">=18"
120
+ },
121
+ "devDependencies": {
122
+ "@payloadcms/next": "^3.77.0",
123
+ "@payloadcms/translations": "^3.77.0",
124
+ "@payloadcms/ui": "^3.77.0",
125
+ "@types/react": "^19.0.0",
126
+ "next": "^15.5.14",
127
+ "payload": "^3.77.0",
128
+ "tsup": "^8.0.0",
129
+ "typescript": "^5.5.0"
130
+ }
131
+ }
package/src/client.ts ADDED
@@ -0,0 +1 @@
1
+ export const SUPPORT_CLIENT_VERSION = '0.2.0'
@@ -0,0 +1,65 @@
1
+ import type { CollectionConfig } from 'payload'
2
+ import type { CollectionSlugs } from '../utils/slugs'
3
+
4
+ // ─── Collection factory ──────────────────────────────────
5
+
6
+ export function createAuthLogsCollection(slugs: CollectionSlugs): CollectionConfig {
7
+ return {
8
+ slug: slugs.authLogs,
9
+ labels: {
10
+ singular: "Journal d'authentification",
11
+ plural: "Journal d'authentification",
12
+ },
13
+ admin: {
14
+ group: 'Support',
15
+ defaultColumns: ['email', 'success', 'action', 'errorReason', 'createdAt'],
16
+ useAsTitle: 'email',
17
+ },
18
+ access: {
19
+ read: ({ req }) => req.user?.collection === slugs.users,
20
+ create: () => false, // Logs are system-generated (server-side uses overrideAccess)
21
+ update: () => false,
22
+ delete: ({ req }) => req.user?.collection === slugs.users,
23
+ },
24
+ fields: [
25
+ {
26
+ name: 'email',
27
+ type: 'email',
28
+ required: true,
29
+ index: true,
30
+ },
31
+ {
32
+ name: 'success',
33
+ type: 'checkbox',
34
+ defaultValue: false,
35
+ index: true,
36
+ },
37
+ {
38
+ name: 'action',
39
+ type: 'select',
40
+ required: true,
41
+ index: true,
42
+ options: [
43
+ { label: 'Connexion', value: 'login' },
44
+ { label: 'Déconnexion', value: 'logout' },
45
+ { label: 'Mot de passe oublié', value: 'forgot-password' },
46
+ { label: 'Inscription', value: 'register' },
47
+ ],
48
+ },
49
+ {
50
+ name: 'errorReason',
51
+ type: 'text',
52
+ admin: { description: 'Raison de l\'échec (mot de passe incorrect, compte verrouillé, etc.)' },
53
+ },
54
+ {
55
+ name: 'ipAddress',
56
+ type: 'text',
57
+ },
58
+ {
59
+ name: 'userAgent',
60
+ type: 'text',
61
+ },
62
+ ],
63
+ timestamps: true,
64
+ }
65
+ }
@@ -0,0 +1,69 @@
1
+ import type { CollectionConfig } from 'payload'
2
+ import type { CollectionSlugs } from '../utils/slugs'
3
+
4
+ // ─── Collection factory ──────────────────────────────────
5
+
6
+ export function createCannedResponsesCollection(slugs: CollectionSlugs): CollectionConfig {
7
+ return {
8
+ slug: slugs.cannedResponses,
9
+ labels: {
10
+ singular: 'Réponse pré-enregistrée',
11
+ plural: 'Réponses pré-enregistrées',
12
+ },
13
+ admin: {
14
+ hidden: true,
15
+ useAsTitle: 'title',
16
+ group: 'Gestion',
17
+ defaultColumns: ['title', 'category', 'updatedAt'],
18
+ },
19
+ fields: [
20
+ {
21
+ name: 'title',
22
+ type: 'text',
23
+ required: true,
24
+ label: 'Titre',
25
+ admin: {
26
+ description: 'Nom court pour identifier la réponse (ex: "Accusé réception")',
27
+ },
28
+ },
29
+ {
30
+ name: 'category',
31
+ type: 'select',
32
+ label: 'Catégorie',
33
+ options: [
34
+ { label: 'Général', value: 'general' },
35
+ { label: 'Bug', value: 'bug' },
36
+ { label: 'Contenu', value: 'content' },
37
+ { label: 'Fonctionnalité', value: 'feature' },
38
+ { label: 'Hébergement', value: 'hosting' },
39
+ { label: 'Clôture', value: 'closing' },
40
+ ],
41
+ },
42
+ {
43
+ name: 'body',
44
+ type: 'textarea',
45
+ required: true,
46
+ label: 'Contenu',
47
+ admin: {
48
+ description: 'Utilisez {{clientName}} pour le prénom du client, {{ticketNumber}} pour le numéro',
49
+ },
50
+ },
51
+ {
52
+ name: 'sortOrder',
53
+ type: 'number',
54
+ label: 'Ordre',
55
+ defaultValue: 0,
56
+ admin: {
57
+ position: 'sidebar',
58
+ },
59
+ },
60
+ ],
61
+ access: {
62
+ create: ({ req }) => req.user?.collection === slugs.users,
63
+ read: ({ req }) => req.user?.collection === slugs.users,
64
+ update: ({ req }) => req.user?.collection === slugs.users,
65
+ delete: ({ req }) => req.user?.collection === slugs.users,
66
+ },
67
+ timestamps: true,
68
+ }
69
+ }
@@ -0,0 +1,98 @@
1
+ import type { CollectionConfig } from 'payload'
2
+ import type { CollectionSlugs } from '../utils/slugs'
3
+
4
+ // ─── Collection factory ──────────────────────────────────
5
+
6
+ export function createChatMessagesCollection(slugs: CollectionSlugs): CollectionConfig {
7
+ return {
8
+ slug: slugs.chatMessages,
9
+ labels: {
10
+ singular: 'Message Chat',
11
+ plural: 'Messages Chat',
12
+ },
13
+ admin: {
14
+ hidden: true,
15
+ useAsTitle: 'message',
16
+ group: 'Support',
17
+ defaultColumns: ['session', 'senderType', 'message', 'createdAt'],
18
+ },
19
+ access: {
20
+ read: ({ req }) => {
21
+ if (req.user?.collection === slugs.users) return true
22
+ if (req.user?.collection === slugs.supportClients) {
23
+ return { client: { equals: req.user.id } }
24
+ }
25
+ return false
26
+ },
27
+ create: ({ req }) => !!req.user,
28
+ update: ({ req }) => req.user?.collection === slugs.users,
29
+ delete: ({ req }) => req.user?.collection === slugs.users,
30
+ },
31
+ fields: [
32
+ {
33
+ name: 'session',
34
+ type: 'text',
35
+ required: true,
36
+ index: true,
37
+ label: 'Session ID',
38
+ admin: { description: 'Identifiant unique de la session de chat' },
39
+ },
40
+ {
41
+ name: 'client',
42
+ type: 'relationship',
43
+ relationTo: slugs.supportClients,
44
+ required: true,
45
+ label: 'Client',
46
+ },
47
+ {
48
+ name: 'senderType',
49
+ type: 'select',
50
+ required: true,
51
+ defaultValue: 'client',
52
+ options: [
53
+ { label: 'Client', value: 'client' },
54
+ { label: 'Agent', value: 'agent' },
55
+ { label: 'Système', value: 'system' },
56
+ ],
57
+ label: 'Type d\'expéditeur',
58
+ },
59
+ {
60
+ name: 'agent',
61
+ type: 'relationship',
62
+ relationTo: slugs.users,
63
+ label: 'Agent',
64
+ admin: {
65
+ condition: (data) => data?.senderType === 'agent',
66
+ },
67
+ },
68
+ {
69
+ name: 'message',
70
+ type: 'textarea',
71
+ required: true,
72
+ label: 'Message',
73
+ },
74
+ {
75
+ name: 'status',
76
+ type: 'select',
77
+ defaultValue: 'active',
78
+ options: [
79
+ { label: 'Actif', value: 'active' },
80
+ { label: 'Fermé', value: 'closed' },
81
+ ],
82
+ label: 'Statut de la session',
83
+ admin: { position: 'sidebar' },
84
+ },
85
+ {
86
+ name: 'ticket',
87
+ type: 'relationship',
88
+ relationTo: slugs.tickets,
89
+ label: 'Ticket lié',
90
+ admin: {
91
+ position: 'sidebar',
92
+ description: 'Ticket créé automatiquement pour cette session',
93
+ },
94
+ },
95
+ ],
96
+ timestamps: true,
97
+ }
98
+ }
@@ -0,0 +1,94 @@
1
+ import type { CollectionConfig } from 'payload'
2
+ import type { CollectionSlugs } from '../utils/slugs'
3
+
4
+ // ─── Collection factory ──────────────────────────────────
5
+
6
+ export function createEmailLogsCollection(slugs: CollectionSlugs): CollectionConfig {
7
+ return {
8
+ slug: slugs.emailLogs,
9
+ labels: {
10
+ singular: 'Journal email',
11
+ plural: 'Journal des emails',
12
+ },
13
+ admin: {
14
+ group: 'Support',
15
+ defaultColumns: ['status', 'action', 'senderEmail', 'subject', 'createdAt'],
16
+ useAsTitle: 'subject',
17
+ enableRichTextRelationship: false,
18
+ },
19
+ access: {
20
+ read: ({ req }) => req.user?.collection === slugs.users,
21
+ create: () => false, // Logs are system-generated (server-side uses overrideAccess)
22
+ update: () => false,
23
+ delete: ({ req }) => req.user?.collection === slugs.users,
24
+ },
25
+ fields: [
26
+ {
27
+ name: 'status',
28
+ type: 'select',
29
+ required: true,
30
+ index: true,
31
+ options: [
32
+ { label: 'Succès', value: 'success' },
33
+ { label: 'Ignoré', value: 'ignored' },
34
+ { label: 'Erreur', value: 'error' },
35
+ ],
36
+ },
37
+ {
38
+ name: 'action',
39
+ type: 'text',
40
+ index: true,
41
+ admin: { description: 'Action effectuée (ticket_created, message_added, ignored, error...)' },
42
+ },
43
+ {
44
+ name: 'senderEmail',
45
+ type: 'email',
46
+ index: true,
47
+ },
48
+ {
49
+ name: 'senderName',
50
+ type: 'text',
51
+ },
52
+ {
53
+ name: 'subject',
54
+ type: 'text',
55
+ },
56
+ {
57
+ name: 'recipientEmail',
58
+ type: 'text',
59
+ admin: { description: 'Champ TO (peut être vide)' },
60
+ },
61
+ {
62
+ name: 'cc',
63
+ type: 'text',
64
+ admin: { description: 'Champ CC' },
65
+ },
66
+ {
67
+ name: 'ticketNumber',
68
+ type: 'text',
69
+ admin: { description: 'Numéro du ticket créé ou mis à jour' },
70
+ },
71
+ {
72
+ name: 'errorMessage',
73
+ type: 'textarea',
74
+ admin: { description: 'Message d\'erreur si échec' },
75
+ },
76
+ {
77
+ name: 'attachments',
78
+ type: 'json',
79
+ admin: { description: 'Métadonnées des pièces jointes [{filename, size, contentType}]' },
80
+ },
81
+ {
82
+ name: 'httpStatus',
83
+ type: 'number',
84
+ admin: { description: 'Code HTTP de la réponse' },
85
+ },
86
+ {
87
+ name: 'processingTimeMs',
88
+ type: 'number',
89
+ admin: { description: 'Temps de traitement en ms' },
90
+ },
91
+ ],
92
+ timestamps: true,
93
+ }
94
+ }
@@ -0,0 +1,99 @@
1
+ import type { CollectionConfig } from 'payload'
2
+ import type { CollectionSlugs } from '../utils/slugs'
3
+
4
+ // ─── Collection factory ──────────────────────────────────
5
+
6
+ export function createKnowledgeBaseCollection(slugs: CollectionSlugs): CollectionConfig {
7
+ return {
8
+ slug: slugs.knowledgeBase,
9
+ labels: {
10
+ singular: 'Article FAQ',
11
+ plural: 'Base de connaissances',
12
+ },
13
+ admin: {
14
+ hidden: true,
15
+ useAsTitle: 'title',
16
+ group: 'Support',
17
+ defaultColumns: ['title', 'category', 'published', 'sortOrder', 'updatedAt'],
18
+ },
19
+ fields: [
20
+ {
21
+ name: 'title',
22
+ type: 'text',
23
+ required: true,
24
+ label: 'Titre / Question',
25
+ },
26
+ {
27
+ name: 'slug',
28
+ type: 'text',
29
+ required: true,
30
+ unique: true,
31
+ label: 'Slug',
32
+ admin: {
33
+ description: 'URL-friendly identifier (auto-generated from title if empty)',
34
+ },
35
+ },
36
+ {
37
+ name: 'category',
38
+ type: 'select',
39
+ required: true,
40
+ label: 'Catégorie',
41
+ options: [
42
+ { label: 'Premiers pas', value: 'getting-started' },
43
+ { label: 'Tickets & Support', value: 'tickets' },
44
+ { label: 'Compte & Profil', value: 'account' },
45
+ { label: 'Facturation', value: 'billing' },
46
+ { label: 'Technique', value: 'technical' },
47
+ { label: 'Général', value: 'general' },
48
+ ],
49
+ },
50
+ {
51
+ name: 'body',
52
+ type: 'richText',
53
+ required: true,
54
+ label: 'Contenu',
55
+ },
56
+ {
57
+ name: 'published',
58
+ type: 'checkbox',
59
+ defaultValue: true,
60
+ label: 'Publié',
61
+ admin: { position: 'sidebar' },
62
+ },
63
+ {
64
+ name: 'sortOrder',
65
+ type: 'number',
66
+ defaultValue: 0,
67
+ label: 'Ordre',
68
+ admin: { position: 'sidebar' },
69
+ },
70
+ ],
71
+ hooks: {
72
+ beforeChange: [
73
+ async ({ data, operation }) => {
74
+ // Auto-generate slug from title if not set
75
+ if (operation === 'create' && !data.slug && data.title) {
76
+ data.slug = data.title
77
+ .toLowerCase()
78
+ .normalize('NFD')
79
+ .replace(/[\u0300-\u036f]/g, '')
80
+ .replace(/[^a-z0-9]+/g, '-')
81
+ .replace(/^-|-$/g, '')
82
+ }
83
+ return data
84
+ },
85
+ ],
86
+ },
87
+ access: {
88
+ create: ({ req }) => req.user?.collection === slugs.users,
89
+ update: ({ req }) => req.user?.collection === slugs.users,
90
+ delete: ({ req }) => req.user?.collection === slugs.users,
91
+ // Public read for published articles (support-clients + unauthenticated)
92
+ read: ({ req }) => {
93
+ if (req.user?.collection === slugs.users) return true
94
+ return { published: { equals: true } }
95
+ },
96
+ },
97
+ timestamps: true,
98
+ }
99
+ }