# Data bridge: your records in the editor

> Offer your software's customers, products or vehicles in the editor through postMessage, without a copy at Mizanpage, and receive events.

Your software remains the source of truth for its data. Rather than copying it to Mizanpage, your page offers it to the editor when the user needs it.

## Make contact

When the editor is ready, it sends the page that opened it:

```json
{ "type": "mizanpage:ready", "session": "4f1c…e9a2", "protocol": 2 }
```

`session` is a random value, different on each opening. **Copy it into each of your messages**: the editor ignores any message that does not carry it.

On your side, always check `event.origin` before reading a message.

## Offer your sources

```js
const EDITOR_ORIGIN = 'https://app.mizanpage.com'
let editorWindow = null
let session = null

function send(message) {
  if (editorWindow && session) editorWindow.postMessage({ ...message, session }, EDITOR_ORIGIN)
}

window.addEventListener('message', (event) => {
  if (event.origin !== EDITOR_ORIGIN) return
  const message = event.data
  if (!message || typeof message.type !== 'string') return

  if (message.type === 'mizanpage:ready') {
    editorWindow = event.source
    session = message.session
    send({ type: 'mizanpage:sources', sources: [
      { source: 'customers', group: 'customer', label: 'Choose a customer', count: 1890 },
    ] })
  }

  if (message.type === 'mizanpage:search' && message.session === session) {
    const records = yourSoftware.search(message.source, message.q).slice(0, 50)
    send({ type: 'mizanpage:records', id: message.id, records: records.map((r) => ({
      key: r.id,
      label: r.label,
      values: { 'customer.name': r.name, 'customer.address': r.address },
    })) })
  }
})
```

The editor then shows a **Choose a customer** button. The person searches, your page answers with at most 50 records, and the person picks one.

## Push values

To fill the document with what the person was looking at in your software:

```js
send({ type: 'mizanpage:values', label: 'Order C-2041', values: { 'customer.name': 'Orlanne Brewery Ltd', 'order.total': '€7,788.00' } })
```

## What happens to this data

It stays in the memory of the editor's tab during the session and only catalog keys are used. The preview sends them to rendering, which reads them and then forgets them without writing anything to a database, a file or a log.

As long as your page announces no sources, the editor offers fictitious demo records.

## Editor events

| Message | When |
| --- | --- |
| `mizanpage:ready` | The editor is ready |
| `mizanpage:search` | The person searches one of your sources |
| `mizanpage:saved` | The draft is saved |
| `mizanpage:published` | A version is published |
| `mizanpage:generated` | A final PDF is produced. `pdf` contains the file |
| `mizanpage:close-requested` | The person leaves the editor: close the iframe |
| `mizanpage:session-expiring` | A delegated session ends in two minutes |
| `mizanpage:session-expired` | The session has ended |

To save before closing it yourself: `send({ type: 'mizanpage:save', id: 1 })`. The editor answers `mizanpage:saved` (or `mizanpage:save-failed`) with the same `id`.

## Limits

20 sources at most. A record has `key` (100 characters), `label` (190) and `values` (4,000 characters per value). A search with no answer within 8 seconds is treated as an empty list.

---

Documentation Mizanpage · Developers › Embedding the editor
https://mizanpage.com/en/docs/integration/pont-donnees/
