> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hotglue.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Listeners

> Use callbacks to respond to Widget events

The `listener` option can be passed in order to respond to various widget events.

## Syntax

```javascript javascript theme={null}
listener: {
  onSourceLinked:
  (source, flow) => console.log(JSON.stringify(source))
}
```

## Supported listeners

### onWidgetOpen

Signature `()`

### onWidgetClose

Signature `()`

### onReconnect

Signature `(entityId, flow)`

| Name     | Type     | Description                                                  |
| -------- | -------- | ------------------------------------------------------------ |
| entityId | `string` | ID of the entity (source/target/connector) being reconnected |
| flow     | `string` | ID of the flow                                               |

### onPopupClose

Signature `(id, flowId)`

| Name   | Type     | Description                      |
| ------ | -------- | -------------------------------- |
| id     | `string` | ID of source/target being linked |
| flowId | `string` | ID of flow being linked          |

### onSourceLinked

Signature `(source, flowId, tenantId)`

| Name     | Type     | Description                                                                             |
| -------- | -------- | --------------------------------------------------------------------------------------- |
| source   | `object` | The source that has been linked. Follows same response structure as ​linked sources API |
| flowId   | `string` | ID of flow that has been linked                                                         |
| tenantId | `string` | ID of the tenant                                                                        |

### onTargetLinked

Signature `(target, flowId)`

| Name   | Type     | Description                                                                            |
| ------ | -------- | -------------------------------------------------------------------------------------- |
| target | `object` | The target that has been linked. Follows same response structure as linked targets API |
| flowId | `string` | ID of flow that has been linked                                                        |

### onConnectorLinked

Signature `(connector, flowId, tenantId)`

| Name      | Type     | Description                        |
| --------- | -------- | ---------------------------------- |
| connector | `object` | The connector that has been linked |
| flowId    | `string` | ID of flow that has been linked    |
| tenantId  | `string` | ID of the tenant                   |

### onSourceLinkCanceled

Signature `(tapId, flowId)`

| Name   | Type     | Description  |
| ------ | -------- | ------------ |
| tapId  | `string` | ID of source |
| flowId | `string` | ID of flow   |

### onConnectorLinkCanceled

Signature `(connectorId, flowId)`

| Name        | Type     | Description     |
| ----------- | -------- | --------------- |
| connectorId | `string` | ID of connector |
| flowId      | `string` | ID of flow      |

### onSourceUnlinked

Signature `(source, flowId)`

| Name   | Type     | Description                       |
| ------ | -------- | --------------------------------- |
| source | `string` | The source that has been unlinked |
| flowId | `string` | ID of flow that has been unlinked |

### onConnectorUnlinked

Signature `(connector, flowId)`

| Name      | Type     | Description                          |
| --------- | -------- | ------------------------------------ |
| connector | `string` | The connector that has been unlinked |
| flowId    | `string` | ID of flow that has been unlinked    |

### onTargetUnlinked

Signature `(target, flowId)`

| Name   | Type     | Description                       |
| ------ | -------- | --------------------------------- |
| target | `string` | The target that has been unlinked |
| flowId | `string` | ID of flow that has been unlinked |

### onTargetLinkCanceled

Signature `(targetId, flowId)`

| Name     | Type     | Description  |
| -------- | -------- | ------------ |
| targetId | `string` | ID of target |
| flowId   | `string` | ID of flow   |

### onSourceLinkFailed

Signature `(source, flowId, tenant, errorMessage)`

| Name         | Type               | Description                          |
| ------------ | ------------------ | ------------------------------------ |
| source       | `string \| object` | The source that failed to link       |
| flowId       | `string`           | ID of flow                           |
| tenant       | `string`           | ID of the tenant                     |
| errorMessage | `string`           | Error message describing the failure |

### onConnectorLinkFailed

Signature `(connector, flowId, tenant, errorMessage)`

| Name         | Type               | Description                          |
| ------------ | ------------------ | ------------------------------------ |
| connector    | `string \| object` | The connector that failed to link    |
| flowId       | `string`           | ID of flow                           |
| tenant       | `string`           | ID of the tenant                     |
| errorMessage | `string`           | Error message describing the failure |

### onTargetLinkFailed

Signature `(target, flowId, tenant, errorMessage)`

| Name         | Type               | Description                          |
| ------------ | ------------------ | ------------------------------------ |
| target       | `string \| object` | The target that failed to link       |
| flowId       | `string`           | ID of flow                           |
| tenant       | `string`           | ID of the tenant                     |
| errorMessage | `string`           | Error message describing the failure |

### onStartJob

Signature `(tap_id, flow_id, user_id)`

| Name     | Type     | Description                         |
| -------- | -------- | ----------------------------------- |
| tap\_id  | `string` | ID of source the job is running for |
| flow\_id | `string` | ID of flow source is linked under   |
| user\_id | `string` | ID of the tenant who started job    |

### onFieldMapSave

Signature `(entityId, flowId, tenantId)`

| Name     | Type     | Description      |
| -------- | -------- | ---------------- |
| entityId | `string` | ID of the entity |
| flowId   | `string` | ID of the flow   |
| tenantId | `string` | ID of the tenant |

### onCustomMappingSave

Signature `(entityId, flowId, tenantId)`

| Name     | Type     | Description      |
| -------- | -------- | ---------------- |
| entityId | `string` | ID of the entity |
| flowId   | `string` | ID of the flow   |
| tenantId | `string` | ID of the tenant |

### onScheduleSave

Signature `(oldSchedule, newSchedule, entityId, flowId, tenantId)`

| Name        | Type             | Description                                                                                                    |
| ----------- | ---------------- | -------------------------------------------------------------------------------------------------------------- |
| oldSchedule | `object \| null` | The previous schedule configuration before the save. May be `null` if no schedule existed.                     |
| newSchedule | `object \| null` | The newly saved schedule configuration. May be `null` if schedule is cleared.                                  |
| entityId    | `string \| null` | ID of the entity (source / target / connector) the schedule applies to. May be `null` if using flow schedules. |
| flowId      | `string`         | ID of the flow                                                                                                 |
| tenantId    | `string`         | ID of the tenant                                                                                               |
