Skip to content

Commit

Permalink
Merge pull request #17 from gofynd/reduce-filter
Browse files Browse the repository at this point in the history
Reducer and filter support added for webhook events
  • Loading branch information
vivek-gofynd authored Jan 28, 2025
2 parents e5aea8c + ff4114b commit 5e858ec
Show file tree
Hide file tree
Showing 4 changed files with 541 additions and 134 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

---
## [v0.7.0] -
## [v0.6.1] -
### Added
- Pub/Sub, temporal, sqs, event_bridge support added.
- Added support for Filters and reducers
- Added `partner_api_routes` to support calling partners server APIs through `PartnerClient`
- Added Support to launch extension Admin inside partners panel
- Added support of passing log level `debug` to SDK from `setupFDK` debug true. This enables curl printing of API calls made from SDK.
Expand Down
72 changes: 62 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,42 @@ fdk_extension_client = setup_fdk({
"notification_email": "test@abc.com", # required
"subscribe_on_install": False, # optional. Default true
"subscribed_saleschannel": "specific", #optional. Default all
"event_map": { # required
'company/brand/create': {
"version": '1',
"handler": handleBrandCreate
"marketplace": True, # to receive marketplace saleschannel events. Only allowed when subscribed_saleschannel is set to specific
"event_map": {
"company/brand/create": {
"version": "1",
"handler": handleBrandCreate,
"provider": "rest" # if not provided, Default is `rest`
},
'company/location/update': {
"version": '1',
"handler": handleLocationUpdate
"company/location/update": {
"version": "1",
"handler": handleLocationUpdate,
},
'application/coupon/create': {
"version": '1',
"handler": handleCouponCreate
"application/coupon/create": {
"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 All @@ -187,6 +211,34 @@ app.add_route(webhook_handler, "/webhook", methods=["POST"])
> 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 `enable_sales_channel_webhook`. To disable receiving events for a saleschannel use function `disable_sales_channel_webhook`.

#### 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.

```python
"webhook_config": {
"api_path": "/api/v1/webhooks",
"notification_email": "test@abc.com",
"subscribe_on_install": False,
"subscribed_saleschannel": "specific",
"marketplace": True,
"event_map": {
'company/brand/update': {
"version": '1',
"handler": handle_webhook,
"filters": {
"query": "$.brand.uid",
"condition": "(uid) => uid === 130"
},
"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

0 comments on commit 5e858ec

Please sign in to comment.