@defra/flood-webchat 0.0.1-beta.52 → 0.0.1-beta.53

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 (42) hide show
  1. package/package.json +1 -1
  2. package/src/client/components/availability/availability.jsx +130 -0
  3. package/src/client/components/availability/availability.scss +77 -0
  4. package/src/client/components/chat/chat.jsx +233 -0
  5. package/src/client/components/chat/chat.scss +259 -0
  6. package/src/client/components/errorSummary/error-summary.jsx +34 -0
  7. package/src/client/components/live-region.jsx +55 -0
  8. package/src/client/components/message/message.jsx +21 -0
  9. package/src/client/components/panel/panel-footer.jsx +9 -0
  10. package/src/client/components/panel/panel-header.jsx +75 -0
  11. package/src/client/components/panel/panel.jsx +163 -0
  12. package/src/client/components/panel/panel.scss +112 -0
  13. package/src/client/components/screens/end-chat.jsx +77 -0
  14. package/src/client/components/screens/feedback.jsx +65 -0
  15. package/src/client/components/screens/pre-chat.jsx +62 -0
  16. package/src/client/components/screens/request-chat.jsx +183 -0
  17. package/src/client/components/screens/settings.jsx +97 -0
  18. package/src/client/components/screens/unavailable.jsx +23 -0
  19. package/src/client/components/skip-link.jsx +42 -0
  20. package/src/client/hooks/useFocusedElements.js +80 -0
  21. package/src/client/hooks/useTextareaAutosize.js +13 -0
  22. package/src/client/index.jsx +33 -0
  23. package/src/client/lib/agent-status-headline.js +17 -0
  24. package/src/client/lib/check-availability.js +8 -0
  25. package/src/client/lib/classnames.js +1 -0
  26. package/src/client/lib/history.js +13 -0
  27. package/src/client/lib/message-notification.js +30 -0
  28. package/src/client/lib/transform-messages.js +47 -0
  29. package/src/client/scss/_objects.scss +33 -0
  30. package/src/client/scss/_settings.scss +101 -0
  31. package/src/client/scss/_tools.scss +33 -0
  32. package/src/client/scss/_utilities.scss +25 -0
  33. package/src/client/store/AppProvider.jsx +183 -0
  34. package/src/client/store/actions-map.js +152 -0
  35. package/src/client/store/constants.js +3 -0
  36. package/src/client/store/reducer.js +31 -0
  37. package/src/client/store/useApp.js +5 -0
  38. package/src/client/store/useChatSdk.js +37 -0
  39. package/src/server/index.js +60 -0
  40. package/src/server/lib/client.js +88 -0
  41. package/src/server/lib/utils.js +23 -0
  42. package/webpack.prod.mjs +0 -7
@@ -0,0 +1,88 @@
1
+ const querystring = require('querystring')
2
+ const axios = require('axios')
3
+ const jwtdecode = require('jwt-decode')
4
+ const { isWithinHours } = require('./utils.js')
5
+
6
+ const contentType = 'application/x-www-form-urlencoded'
7
+
8
+ const authenticate = async ({ authenticationUri, authorisation, accessKey, accessSecret }) => {
9
+ const url = new URL(authenticationUri)
10
+ const body = querystring.stringify({
11
+ grant_type: 'password',
12
+ username: accessKey,
13
+ password: accessSecret
14
+ })
15
+
16
+ const auth = await axios.post(url.href, body, {
17
+ signal: AbortSignal.timeout(3000),
18
+ headers: {
19
+ Host: url.host,
20
+ 'Content-Type': contentType,
21
+ Authorization: authorisation
22
+ }
23
+ })
24
+
25
+ return {
26
+ token: auth.data.access_token,
27
+ tokenType: auth.data.token_type,
28
+ tenantId: jwtdecode(auth.data.id_token)?.tenantId
29
+ }
30
+ }
31
+
32
+ const getApiBaseUrl = async ({ wellKnownUri, tenantId }) => {
33
+ const url = new URL(wellKnownUri)
34
+ url.searchParams.set('tenantId', tenantId)
35
+
36
+ const { data } = await axios.get(url.href, {
37
+ headers: {
38
+ Host: url.host
39
+ },
40
+ signal: AbortSignal.timeout(3000)
41
+ })
42
+
43
+ return data.api_endpoint
44
+ }
45
+
46
+ const getActivity = async ({ tokenType, token, baseUrl, skillEndpoint, maxQueueCount }) => {
47
+ const url = new URL(skillEndpoint, baseUrl)
48
+
49
+ const skill = await axios.get(url.href, {
50
+ signal: AbortSignal.timeout(3000),
51
+ headers: {
52
+ Host: url.host,
53
+ Authorization: `${tokenType} ${token}`,
54
+ 'Content-Type': contentType
55
+ }
56
+ })
57
+
58
+ const activity = skill.data.skillActivity[0]
59
+
60
+ return {
61
+ hasCapacity: activity.queueCount < maxQueueCount,
62
+ hasAgentsAvailable: activity.agentsAvailable >= 1
63
+ }
64
+ }
65
+
66
+ const getIsOpen = async ({ baseUrl, token, tokenType, hoursEndpoint }) => {
67
+ const url = new URL(hoursEndpoint, baseUrl)
68
+
69
+ const hours = await axios.get(url.href, {
70
+ signal: AbortSignal.timeout(3000),
71
+ headers: {
72
+ Host: url.host,
73
+ Authorization: `${tokenType} ${token}`,
74
+ 'Content-Type': contentType
75
+ }
76
+ })
77
+
78
+ const days = hours.data.resultSet.hoursOfOperationProfiles[0].days
79
+
80
+ return isWithinHours(days)
81
+ }
82
+
83
+ module.exports = {
84
+ authenticate,
85
+ getApiBaseUrl,
86
+ getIsOpen,
87
+ getActivity
88
+ }
@@ -0,0 +1,23 @@
1
+ const { DateTime } = require('luxon')
2
+
3
+ const getHour = time => Number(time.split(':')[0])
4
+
5
+ const isWithinHours = (days, date) => {
6
+ const now = date ? DateTime.fromISO(date) : DateTime.local()
7
+ now.setZone('Europe/London')
8
+
9
+ const newDate = date ? new Date(date) : new Date()
10
+
11
+ const today = newDate.toLocaleDateString('en-GB', { weekday: 'long' })
12
+ const dateParts = newDate.toLocaleDateString('en-GB').split('/')
13
+
14
+ const todaysAvailability = days.find(item => item.day === today)
15
+ const todaysDateTimeOpen = DateTime.local(Number(dateParts[2]), Number(dateParts[1]), Number(dateParts[0]), getHour(todaysAvailability.openTime))
16
+ const todaysDateTimeClose = DateTime.local(Number(dateParts[2]), Number(dateParts[1]), Number(dateParts[0]), getHour(todaysAvailability.closeTime))
17
+
18
+ return now.diff(todaysDateTimeOpen).milliseconds >= 0 && now.diff(todaysDateTimeClose).milliseconds <= 0
19
+ }
20
+
21
+ module.exports = {
22
+ isWithinHours
23
+ }
package/webpack.prod.mjs DELETED
@@ -1,7 +0,0 @@
1
- import { merge } from 'webpack-merge'
2
-
3
- import common from './webpack.config.mjs'
4
-
5
- export default merge(common, {
6
- mode: 'production'
7
- })