Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce and filter support added for webhook event #73

Merged
merged 13 commits into from
Jan 28, 2025
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ let fdkClient = setupFdk({
notification_email: "[email protected]", // required
subscribe_on_install: false, //optional. Default true
subscribed_saleschannel: 'specific', //optional. Default all
marketplace: true, // to receive marketplace saleschannel events. Only allowed when subscribed_saleschannel is set to specific
event_map: { // required
'company/brand/create': {
version: '1',
Expand All @@ -167,6 +168,27 @@ let fdkClient = setupFdk({
version: '1',
topic: 'coupon_create_kafka_topic',
provider: 'kafka'
},
'company/brand/update': {
version: '1',
topic: "company-brand-create",
provider: 'pub_sub'
},
'extension/extension/install': {
version: '1',
queue: "extension-install",
workflow_name: "extension",
provider: 'temporal'
},
'company/location/create': {
version: '1',
queue: "company-location-create",
provider: 'sqs'
},
'company/product-size/create': {
version: '1',
event_bridge_name: "company-product-size-create",
provider: 'event_bridge'
}
}
},
Expand Down Expand Up @@ -197,7 +219,32 @@ app.post('/api/v1/webhooks', async (req, res, next) => {

> Setting `subscribed_saleschannel` as "specific" means, you will have to manually subscribe saleschannel level event for individual saleschannel. Default value here is "all" and event will be subscribed for all sales channels. For enabling events manually use function `enableSalesChannelWebhook`. To disable receiving events for a saleschannel use function `disableSalesChannelWebhook`.

#### Filters and reducers in webhook events

A filter and reducer can be provided to refine the data delivered for each subscribed event. The Filter functionality allows selective delivery of data by specifying conditions based on JSONPath queries and logical operators. Reducer allow customization of the payload structure by specifying only the fields needed by the subscriber. The reducer extracts fields from the event’s data and restructures them as needed.

```javascript
webhook_config: {
api_path: "/v1.0/webhooks",
notification_email: "[email protected]",
marketplace: true,
subscribed_saleschannel: 'specific',
event_map: {
'company/brand/update': {
version: '1',
handler: handleExtensionUninstall,
filters: {
query: "$.brand.uid",
condition: "(uid) => uid === 238"
},
reducer: {
brand_name: "$.brand.name",
logo_link: "$.brand.logo"
}
}]
}
}
```
##### How webhook registery subscribes to webhooks on Fynd Platform?
After webhook config is passed to setupFdk whenever extension is launched to any of companies where extension is installed or to be installed, webhook config data is used to create webhook subscriber on Fynd Platform for that company.

Expand Down
Loading