# Browser package

Copy it in with `scripts/vendor.sh js <dest>`. The functions are in `telltale-web.js`; the React components are in `react/`.

## Functions

### `init(options)`

Starts error reporting. Call once, before the app renders; later calls do nothing.

| Option | Default | Meaning |
|---|---|---|
| `app` | none | The app name records are filed under. |
| `endpoint` | `''` | The app's API prefix, such as `/api`. Reports go to `{endpoint}/_telltale/client` and feedback to `{endpoint}/feedback`. |
| `release` | `'dev'` | Release label sent with each report. |
| `flushMs` | `2000` | How often queued reports are sent. |
| `maxBatch` | `20` | Most reports per request. |
| `scrubExtra` | `[]` | Extra regexes to scrub from report text. |
| `listeners` | `true` | Listen for uncaught errors and unhandled promise rejections. |
| `reportHttpErrors` | `false` | Also report failed API responses. Leave off when the API has telltale, which records them itself. |

### `configure({ reportHttpErrors, authFetch })`

Changes options after `init`. `authFetch` is your app's own authenticated fetch; `sendFeedback` uses it so the server knows who is signed in. Error reports never use it.

### `wrapFetch(fetch)`

Returns a fetch that adds the `X-Telltale-Client` and `X-Telltale-Session` headers to API calls and reports network failures. Use as `window.fetch = wrapFetch(window.fetch)`. With axios, call `axiosInterceptor(axios)` instead.

### `setRoute(pattern)`

Sets the current route pattern, such as `/projects/:id`. Call it on each route change. Pass the pattern, never the real URL.

### `report(code, { message, detail, route })`

Reports one event yourself, such as a crash your error page caught.

### `sendFeedback({ text, category, contact, page, entity_type, entity_id })`

Sends a feedback note. Returns a promise.

### Others

`flush()` sends queued reports now. `shutdown()` stops reporting. `scrub(text)` returns text with private details replaced. `errDetail(err)` makes a short, scrubbed description of an error. `getSession()` returns the session id.

## `FeedbackButton`

```jsx
import { FeedbackButton } from './vendor/telltale/react/FeedbackButton.jsx'
```

| Prop | Default | Meaning |
|---|---|---|
| `label` | `'Send feedback'` | Button text. |
| `placement` | `'bottom-right'` | `bottom-left`, `top-right`, `top-left` or `inline`. |
| `categories` | `['bug', 'idea', 'question', 'other']` | Categories offered. |
| `showContact` | `true` | Show the contact box. |
| `signedInAs` | none | Shows "Sending as ..." in place of the contact box. Display only. |
| `title`, `sentTitle`, `sentText` | | Dialog text. |
| `send` | `sendFeedback` | Function that sends the note. |
| `onSent` | none | Called with the result after a note is sent. |
| `open`, `onOpenChange` | none | Control the dialog yourself. |
| `hideTrigger` | `false` | Hide the button, for a dialog opened from your own menu. |
| `className`, `style` | none | Styling for the button. |

## `ErrorBoundary`

```jsx
import { ErrorBoundary } from './vendor/telltale/react/ErrorBoundary.jsx'
```

Reports a render crash, then shows `fallback`. `fallback` is a node or a function `(error, reset) => node`. `onError(error, info)` is called after the report.

## `TelltaleConsole`

```jsx
import { TelltaleConsole } from './vendor/telltale/react/TelltaleConsole.jsx'
import './vendor/telltale/console/console.css'
```

| Prop | Default | Meaning |
|---|---|---|
| `apiBase` | required | Where the telltale API lives, such as `/api/_telltale`. |
| `fetch` | none | Your app's authenticated fetch. With it, the console never asks for a key. |
| `app` | first app listed | App to show first. |
| `view` | `'inbox'` | `inbox` or `stats`. |
| `stage` | `'todo'` | `todo`, `reported`, `suggested`, `filed` or `closed`. |
| `open` | none | `{type, id}` of an item to open on load. |
| `className`, `style` | none | Styling for the wrapper. |

Without React, `mountConsole(element, options)` from `console/console.js` takes the same options.
