Skip to content

Commit 5e858ec

Browse files
authored
Merge pull request #17 from gofynd/reduce-filter
Reducer and filter support added for webhook events
2 parents e5aea8c + ff4114b commit 5e858ec

File tree

4 files changed

+541
-134
lines changed

4 files changed

+541
-134
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
---
8-
## [v0.7.0] -
8+
## [v0.6.1] -
99
### Added
10+
- Pub/Sub, temporal, sqs, event_bridge support added.
11+
- Added support for Filters and reducers
1012
- Added `partner_api_routes` to support calling partners server APIs through `PartnerClient`
1113
- Added Support to launch extension Admin inside partners panel
1214
- Added support of passing log level `debug` to SDK from `setupFDK` debug true. This enables curl printing of API calls made from SDK.

README.md

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,42 @@ fdk_extension_client = setup_fdk({
149149
"notification_email": "test@abc.com", # required
150150
"subscribe_on_install": False, # optional. Default true
151151
"subscribed_saleschannel": "specific", #optional. Default all
152-
"event_map": { # required
153-
'company/brand/create': {
154-
"version": '1',
155-
"handler": handleBrandCreate
152+
"marketplace": True, # to receive marketplace saleschannel events. Only allowed when subscribed_saleschannel is set to specific
153+
"event_map": {
154+
"company/brand/create": {
155+
"version": "1",
156+
"handler": handleBrandCreate,
157+
"provider": "rest" # if not provided, Default is `rest`
156158
},
157-
'company/location/update': {
158-
"version": '1',
159-
"handler": handleLocationUpdate
159+
"company/location/update": {
160+
"version": "1",
161+
"handler": handleLocationUpdate,
160162
},
161-
'application/coupon/create': {
162-
"version": '1',
163-
"handler": handleCouponCreate
163+
"application/coupon/create": {
164+
"version": "1",
165+
"topic": "coupon_create_kafka_topic",
166+
"provider": "kafka"
167+
},
168+
"company/brand/update": {
169+
"version": "1",
170+
"topic": "company-brand-create",
171+
"provider": "pub_sub"
172+
},
173+
"extension/extension/install": {
174+
"version": "1",
175+
"queue": "extension-install",
176+
"workflow_name": "extension",
177+
"provider": "temporal"
178+
},
179+
"company/location/create": {
180+
"version": "1",
181+
"queue": "company-location-create",
182+
"provider": "sqs"
183+
},
184+
"company/product-size/create": {
185+
"version": "1",
186+
"event_bridge_name": "company-product-size-create",
187+
"provider": "event_bridge"
164188
}
165189
}
166190
}
@@ -187,6 +211,34 @@ app.add_route(webhook_handler, "/webhook", methods=["POST"])
187211
> 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`.
188212
189213

214+
#### Filters and reducers in webhook events
215+
216+
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.
217+
218+
```python
219+
"webhook_config": {
220+
"api_path": "/api/v1/webhooks",
221+
"notification_email": "test@abc.com",
222+
"subscribe_on_install": False,
223+
"subscribed_saleschannel": "specific",
224+
"marketplace": True,
225+
"event_map": {
226+
'company/brand/update': {
227+
"version": '1',
228+
"handler": handle_webhook,
229+
"filters": {
230+
"query": "$.brand.uid",
231+
"condition": "(uid) => uid === 130"
232+
},
233+
"reducer": {
234+
"brand_name": "$.brand.name",
235+
"logo_link": "$.brand.logo"
236+
}
237+
}
238+
}
239+
}
240+
```
241+
190242
##### How webhook registery subscribes to webhooks on Fynd Platform?
191243
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.
192244

0 commit comments

Comments
 (0)