@tugitark/react-widget 1.4.4 → 1.4.6

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.
package/index.md CHANGED
@@ -10,7 +10,7 @@ Also see [the original integration guide](https://www.tugitark.com/chat-setup) f
10
10
 
11
11
  This is the smallest number of properties that you can pass to `<TugiWidget>` and have it still operate correctly. These properties are given to you on signing up with Tugi Tark and must be entered accurately.
12
12
 
13
- ```javascript
13
+ ```react
14
14
  import TugiWidget from '@tugitark/react-widget';
15
15
 
16
16
  function Component(props) {
@@ -34,7 +34,7 @@ If your server has the standard `/.tugi` endpoints (as provided by our back-end
34
34
 
35
35
  This is a more extensive widget example, with colour-scheme customisation and an explicit JWT lookup function. The HTTP and websocket addresses are also specified, though match the defaults.
36
36
 
37
- ```javascript
37
+ ```react
38
38
  import TugiWidget from '@tugitark/react-widget';
39
39
 
40
40
  interface Props {
@@ -108,7 +108,7 @@ A "proactive" message can be used to detect that a player has a problem and offe
108
108
 
109
109
  If both `tugiFn` and `user` are missing from the `<TugiWidget>` properties then the widget goes in to the special free mode (more accurately, both must be `null` or `undefined` - if you want a user who isn't logged in pass a `user` of `''`). In this mode the user cannot send or receive any messages, they can only view a few pre-defined FAQ-style help topics:
110
110
 
111
- ```javascript
111
+ ```react
112
112
  import TugiWidget from '@tugitark/react-widget';
113
113
 
114
114
  function Component(props) {
@@ -152,7 +152,7 @@ The following optional properties are shared with the full version:
152
152
 
153
153
  While there can be only one widget on the page there can be multiple `<TugiWidget>` components at once. Which one will be used is non-deterministic - even if you have one `<TugiWidget>` with `visible={true}` and another one with `visible={false}` this will not guarantee that the visible one is the one that gets shown, the invisible one may be "shown", resulting in neither being seen. The one selected is based on internal render and update orders. Further, having two at once may result in the widget being constantly unloaded and reloaded even when nothing has changed as the underlying code flips repeatedly between them. If you have two versions of the widget shown in different circumstances then make sure that the whole component is conditional:
154
154
 
155
- ```javascript
155
+ ```react
156
156
  return (
157
157
  disabled
158
158
  ? <TugiWidget
@@ -186,7 +186,7 @@ return (
186
186
  );
187
187
  ```
188
188
 
189
- [Click here](using-library.md) to see how this component wraps the underlying [@tugitark/declarative-widget](https://gitlab.com/tugitark/integration/libraries/javascript/declarative-widget) library in a react component.
189
+ [Click here](implementation.md) to see how this component wraps the underlying [@tugitark/declarative-widget](https://gitlab.com/tugitark/integration/libraries/javascript/declarative-widget) library in a react component.
190
190
 
191
- [Click here](from-scratch.md) to get a better understanding of everything that that library is doing behind the scenes to inject the main widget script in to a page and initialise it.
191
+ [Click here](https://gitlab.com/tugitark/integration/libraries/javascript/declarative-widget/implementation.md) to get a better understanding of everything that that library is doing behind the scenes to inject the main widget script in to a page and initialise it.
192
192
 
package/package.json CHANGED
@@ -1,11 +1,9 @@
1
1
  {
2
2
  "name": "@tugitark/react-widget",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Wraps the tugitark widget in a React component.",
5
5
  "scripts": {
6
- "build": "npx esbuild index.ts --target=es6 --outfile=index.js && sed -i 's/\\bconst\\b/var/g' index.js && sed -i 's/\\blet\\b/var/g' index.js && npx esbuild index.js --allow-overwrite --minify --target=es5 --outfile=index.js && npx tsc --noErrorTruncation --declaration --emitDeclarationOnly --target es6 --module nodenext --moduleResolution nodenext --outDir . index.ts",
7
- "release": "npm publish --access public",
8
- "prerelease": "npm run build"
6
+ "build": "npx esbuild index.ts --target=es6 --outfile=index.js && sed -i 's/\\bconst\\b/var/g' index.js && sed -i 's/\\blet\\b/var/g' index.js && npx esbuild index.js --allow-overwrite --minify --target=es5 --outfile=index.js && npx tsc --noErrorTruncation --declaration --emitDeclarationOnly --target es6 --module nodenext --moduleResolution nodenext --outDir . index.ts"
9
7
  },
10
8
  "files": [
11
9
  "index.d.ts",
@@ -15,7 +13,7 @@
15
13
  "from-scratch.md"
16
14
  ],
17
15
  "dependencies": {
18
- "@tugitark/declarative-widget": "^1.2.3"
16
+ "@tugitark/declarative-widget": "^1.2.4"
19
17
  },
20
18
  "peerDependencies": {
21
19
  "react": ">=0.0.0"
package/from-scratch.md DELETED
@@ -1,86 +0,0 @@
1
- Reimplementing The Widget From Scratch
2
- ========================================
3
-
4
- This library uses [@tugitark/declarative-widget](https://gitlab.com/tugitark/integration/libraries/javascript/declarative-widget) to handle the heavy lifting of detecting property changes, downloading the widget script, and (un)loading the actual widget tags on changes. Basically that library converts the imperative and static Tugi Tark chat widget in to a functional equivalent. All this library does is call that library from inside a component.
5
-
6
- The code below demonstrates the basics of what is going on behind the scenes within that library. As detailed in [the original integration guide](https://www.tugitark.com/chat-setup), at some point the widget implementation must be imported using `<script>` and initialised via `window.tugiWidget.initialize()`. This example handles those operations by dynamically loading the script via javascript, then calling the API method once the loading is completed. The full version also handles unloading of the script for updates that cannot be applied after initialisation. However, unloading the widget was never an intended operation and so how it is done uses several internal details that should not be replicated in your code, and will not br replicated here.
7
-
8
- Steps
9
- =======
10
-
11
- * *Load the script*
12
-
13
- Create a `<script>` tag dynamically and inject it in to the page (if required):
14
-
15
- ```javascript
16
- function loadScript() {
17
- if (window.tugiWidget) {
18
- // The script already exists.
19
- initialise();
20
- return;
21
- }
22
- const script = document.createElement('script');
23
- // This attribute is recommended in the integration guide but may not work on `http` (testing).
24
- //script.crossOrigin = 'anonymous';
25
- script.async = true;
26
- script.src = 'https://app.tugi.ai/tugi.widget/script';
27
- script.onload = initialise;
28
- script.onerror = (e) => console.error(e);
29
- script.setAttribute('tugi-widget-script', 'true');
30
- document.head.appendChild(script);
31
- }
32
- ```
33
-
34
- * *Initialise the widget*
35
-
36
- The details here are partially supplied by Tugi Tark (e.g. the `brandId`), and otherwise customisable by you:
37
-
38
- ```javacript
39
- function initialise() {
40
- window.tugiWidget.initialize({
41
- jwtFn: getUserToken,
42
- tenantId: 'gb-casinos-ltd',
43
- brandId: 'a040050697fc4b2db16acfbbad1d0da4',
44
- brandName: 'Super Casino',
45
- httpUrl: 'https://app.tugi.ai/tugi.widget',
46
- wsUrl: 'wss://ws.tugi.ai',
47
- customize: {
48
- title: 'Super Casino Chat',
49
- showTitle: true,
50
- fontColor: PRIMARY_COLOUR,
51
- primaryColor: PRIMARY_COLOUR,
52
- secondaryColor: 'hsla(36, 100%, 50%, 1)',
53
- homePageBackgroundColor: 'hsla(36, 100%, 37%, 0.2)',
54
- homePageTextColor: PRIMARY_COLOUR,
55
- },
56
- });
57
- }
58
- ```
59
-
60
- * *Request the JWT*
61
-
62
- This requires a user that is logged in:
63
-
64
- ```javacript
65
- async function getUserToken() {
66
- const response = await fetch('/users/current/tugi-token');
67
- if (response.ok) {
68
- const jwt = await response.text();
69
- if (jwt !== '') return jwt;
70
- }
71
- return null;
72
- }
73
- ```
74
-
75
- Note that the standard endpoint for getting JWTs is `/.tugi/jwt/issue?id=<user-id>`. The default code will use this endpoint if no `jwtFn` is supplied.
76
-
77
- * *Refesh the widget*
78
-
79
- If a user logs in after loading the widget tell it so it can update the JWT:
80
-
81
- ```javacript
82
- if (window.tugiWidget?.isInitialized()) {
83
- window.tugiWidget.refresh();
84
- }
85
- ```
86
-
package/using-library.md DELETED
@@ -1,18 +0,0 @@
1
- Reimplementing The Widget With A Library
2
- ==========================================
3
-
4
- This library uses [@tugitark/declarative-widget](https://gitlab.com/tugitark/integration/libraries/javascript/declarative-widget) to handle the heavy lifting of detecting property changes, downloading the widget script, and (un)loading the actual widget tags on changes. Basically that library converts the imperative and static Tugi Tark chat widget in to a functional equivalent. All this library does is call that library from inside a component.
5
-
6
- The code below, while unoptimised, demonstrates how this compoment wraps that library. See [the source code](index.ts) for more details.
7
-
8
- ```typescript
9
- import render, { type Props } from '@tugitark/declarative-widget';
10
-
11
- export default function TugiWidget(props: Props) {
12
- render(props);
13
- return null;
14
- }
15
- ```
16
-
17
- The full version contains a few additional checks to ensure that certain events are only triggered once per component instance. But other than that, this is essentially all there is to this wrapper. All the complexities of reloading and updating the actual widget implementation itself are handled in the *declarative-widget* library itself. See [the from-scratch example](from-scratch.md) for a deeper explanation of what is happening behind the scenes in that library.
18
-