cobrowse-agent-ui 1.6.0 → 1.7.0-rc.10
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/README.md +96 -7
- package/dist/Loader-Bu0VYaM7.js +2413 -0
- package/dist/Loader-Bu0VYaM7.js.map +1 -0
- package/dist/cobrowse-agent-ui.css +2 -1
- package/dist/cobrowse-agent-ui.d.ts +448 -6
- package/dist/cobrowse-agent-ui.js +1192 -455
- package/dist/cobrowse-agent-ui.js.map +1 -1
- package/dist/integrations.d.ts +4 -2
- package/dist/integrations.js +115 -138
- package/dist/integrations.js.map +1 -1
- package/dist/session/demo-session.html +107 -104
- package/package.json +42 -33
- package/dist/index-fBWDR3rY.js +0 -1337
- package/dist/index-fBWDR3rY.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,94 @@
|
|
|
1
1
|
# Cobrowse Agent UI
|
|
2
2
|
|
|
3
|
+
## Development
|
|
4
|
+
|
|
5
|
+
This project uses [Vite+](https://viteplus.dev/guide/) (`vp`) as its toolchain for the dev server, builds, formatting,
|
|
6
|
+
linting and type checking.
|
|
7
|
+
|
|
8
|
+
### Setup
|
|
9
|
+
|
|
10
|
+
1. Install the global `vp` CLI:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# macOS / Linux
|
|
14
|
+
curl -fsSL https://vite.plus | bash
|
|
15
|
+
|
|
16
|
+
# Windows (PowerShell)
|
|
17
|
+
irm https://vite.plus/ps1 | iex
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Open a new shell and run `vp help` to confirm it's on your `PATH`. `vp` manages the Node.js runtime and package manager
|
|
21
|
+
for you. The npm version is pinned through `devEngines` in `package.json` and is downloaded automatically if it's missing.
|
|
22
|
+
|
|
23
|
+
2. Install dependencies:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
vp install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
3. Install the Git hooks:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
vp config
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The project's `.npmrc` sets `ignore-scripts=true`, so installing dependencies doesn't run the `prepare` script and
|
|
36
|
+
the hooks need installing once per clone. `vp config` installs them in `.vite-hooks`. The pre-commit hook runs
|
|
37
|
+
`vp check --fix` on staged files.
|
|
38
|
+
|
|
39
|
+
If Node.js or npm behave unexpectedly, run `vp env doctor`.
|
|
40
|
+
|
|
41
|
+
### Commands
|
|
42
|
+
|
|
43
|
+
| Command | Description |
|
|
44
|
+
| ------------- | ------------------------------------------------------------ |
|
|
45
|
+
| `vp dev` | Start the dev server with the kitchen sink app from `src/` |
|
|
46
|
+
| `vp build` | Build the library into `dist/` |
|
|
47
|
+
| `vp check` | Format, lint and type check |
|
|
48
|
+
| `vp run lint` | Lint (warnings fail), plus `i18next-cli` lint. CI runs this. |
|
|
49
|
+
| `vp run i18n` | Extract translation keys into the locale files |
|
|
50
|
+
|
|
51
|
+
**Note:** `vp <name>` runs a built-in Vite+ command, while `vp run <name>` runs a `package.json` script. The two can do
|
|
52
|
+
different things, so use `vp run` for the scripts defined in this project.
|
|
53
|
+
|
|
54
|
+
The npm equivalents (`npm install`, `npm run <script>`) still work, even without the global `vp` CLI, since the scripts
|
|
55
|
+
use the project-local `vp` from the `vite-plus` package. CI uses them too. Prefer `vp` for local development, though, so
|
|
56
|
+
commands run with the Node.js and npm versions Vite+ manages.
|
|
57
|
+
|
|
58
|
+
For linting in your editor, install the [Oxc extension](https://marketplace.visualstudio.com/items?itemName=oxc.oxc-vscode)
|
|
59
|
+
for VS Code or the equivalent for [other editors](https://viteplus.dev/guide/ide-integration).
|
|
60
|
+
|
|
61
|
+
## Accounts (experimental)
|
|
62
|
+
|
|
63
|
+
`AccountsProvider` lists the user's accounts and keeps one selected, stored in local storage so it survives a reload.
|
|
64
|
+
While mounted it owns the SDK's license: once the list has loaded, the license is kept on the account shown, so that
|
|
65
|
+
is the account requests are made against, and on unmount the SDK gets back the license it had. The selection starts
|
|
66
|
+
from the stored one, else from a license set on the SDK before mounting, and resolves to the first account when the
|
|
67
|
+
list doesn't contain it. The provider needs a
|
|
68
|
+
`CobrowseProvider` above it, and should be mounted once the user is signed in, as an empty list, which the API returns
|
|
69
|
+
to a signed-out request, resolves to no account and clears the SDK's license:
|
|
70
|
+
|
|
71
|
+
```jsx
|
|
72
|
+
<CobrowseProvider cobrowse={cobrowse}>
|
|
73
|
+
<AccountsProvider>
|
|
74
|
+
<App />
|
|
75
|
+
</AccountsProvider>
|
|
76
|
+
</CobrowseProvider>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Inside it, `useActiveAccount` gives the selected account and the function to select another, `useAccountsContext` the
|
|
80
|
+
list as `useListAccounts` returns it, and `useActiveAccountContext` the selection along with `isResolved`, true once
|
|
81
|
+
the selection has been matched against the loaded list or the list failed to load:
|
|
82
|
+
|
|
83
|
+
```jsx
|
|
84
|
+
const [account, setActiveAccount] = useActiveAccount()
|
|
85
|
+
const { data: accounts, refetch, unshift } = useAccountsContext()
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`setActiveAccount` takes an SDK account, and puts one the list doesn't contain yet, e.g. one just created, first in
|
|
89
|
+
the list. A bare `{ license_key }` can be selected before the list has loaded, e.g. an account forced from the URL,
|
|
90
|
+
and is resolved against the list once it arrives. After that it has to be in the list, or `setActiveAccount` throws.
|
|
91
|
+
|
|
3
92
|
## Localization
|
|
4
93
|
|
|
5
94
|
### Change active locale at runtime
|
|
@@ -10,16 +99,16 @@ achieve this from an app that's also using `i18next` to handle localization.
|
|
|
10
99
|
```js
|
|
11
100
|
// i18n.js
|
|
12
101
|
|
|
13
|
-
import i18n from 'i18next'
|
|
14
|
-
import { bindI18n } from 'cobrowse-agent-ui'
|
|
102
|
+
import i18n from 'i18next'
|
|
103
|
+
import { bindI18n } from 'cobrowse-agent-ui'
|
|
15
104
|
|
|
16
105
|
i18n.init({
|
|
17
106
|
// ...
|
|
18
|
-
})
|
|
107
|
+
})
|
|
19
108
|
|
|
20
|
-
bindI18n(i18n)
|
|
109
|
+
bindI18n(i18n)
|
|
21
110
|
|
|
22
|
-
export default i18n
|
|
111
|
+
export default i18n
|
|
23
112
|
```
|
|
24
113
|
|
|
25
114
|
### Adding new locales
|
|
@@ -27,11 +116,11 @@ export default i18n;
|
|
|
27
116
|
To add a new locale follow these steps:
|
|
28
117
|
|
|
29
118
|
- Add a new entry to the `locales` array inside `i18next.config.ts`.
|
|
30
|
-
- Run the `
|
|
119
|
+
- Run the `vp run i18n` command to generate a new locale file.
|
|
31
120
|
- Import the new locale JSON file inside `lib/i18n/instance.ts` and add it to the `resources` object (in the i18n instance
|
|
32
121
|
configuration) keyed by the locale key.
|
|
33
122
|
- Import the relevant `date-fns` locale inside `lib/i18n/instance.ts`.
|
|
34
123
|
- Add a new entry to `dateLocales` inside `lib/i18n/instance.ts`.
|
|
35
124
|
|
|
36
125
|
**Note:** ensure the locale code matches the ones provided by the
|
|
37
|
-
[date-fns library](https://github.com/date-fns/date-fns/tree/main/src/locale) as these are used to localize dates as well.
|
|
126
|
+
[date-fns library](https://github.com/date-fns/date-fns/tree/main/pkgs/core/src/locale) as these are used to localize dates as well.
|