Skip to content

Commit 171cf52

Browse files
Reducer and filter support added (#50)
* V3 api integrated and readme updated * unused variable removed * Type marketplace changes added * readme updated * filters and reducer support added * Readme Updated * Issue with key fixed * Readme Updated * version changed
1 parent 3fdb77a commit 171cf52

18 files changed

+640
-111
lines changed

README.md

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,39 @@ ext :
278278
api_path: "/webhook" #<POST API URL>
279279
notification_email: <EMAIL_ID>
280280
subscribe_on_install: false, #optional. Default true
281-
subscribed_saleschannel: 'all' #Can be 'SPECIFIC'/'EMPTY'
281+
subscribed_saleschannel: 'specific' #Optional. Default all
282+
marketplace: true, # to receive marketplace saleschannel events. Only allowed when subscribed_saleschannel is set to specific
282283
event_map:
283-
- name: 'product/create'
284+
- name: 'product/update'
284285
handler: productCreateHandler #Make sure this matches the Component Bean name
285286
category: 'company'
286287
version: '1'
287288
provider: 'rest' # If not provided, Default is 'rest'
288-
-
289-
name: 'product/delete'
289+
- name: 'product/delete'
290290
handler: productDeleteHandler
291291
category: 'company'
292292
version: '1'
293293
provider: 'kafka'
294-
294+
- name: "brand/create"
295+
topic: "company-brand-create"
296+
category: "company"
297+
version: 1
298+
provider: "pub_sub"
299+
- name: "extension/install"
300+
queue: "extension-install"
301+
workflow_name: "extension"
302+
version: 1
303+
provider: "temporal"
304+
- name: "location/create"
305+
queue: "company-location-create"
306+
category: "company"
307+
version: 1
308+
provider: "sqs"
309+
- name: "product-size/create"
310+
event_bridge_name: "company-product-size-create"
311+
category: "company"
312+
version: 1
313+
provider: "event_bridge"
295314
```
296315
297316
2. Create Handlers for each event which is mentioned in the Event Map (as specified above)
@@ -342,6 +361,68 @@ public class WebhookController {
342361
>
343362
> To disable receiving events for a saleschannel use function `disableSalesChannelWebhook`.
344363
364+
365+
```java
366+
import com.fynd.extension.model.Extension;
367+
import com.sdk.platform.PlatformClient;
368+
import com.fynd.extension.service.WebhookService;
369+
import jakarta.servlet.http.HttpServletRequest;
370+
import lombok.extern.slf4j.Slf4j;
371+
import org.springframework.web.bind.annotation.GetMapping;
372+
import org.springframework.web.bind.annotation.RequestMapping;
373+
import org.springframework.web.bind.annotation.RestController;
374+
375+
@RestController
376+
@RequestMapping("/api")
377+
@Slf4j
378+
public class PlatformController extends BasePlatformController {
379+
@GetMapping(value = "/enableSalesChannelWebhook", produces = "application/json")
380+
public String getProducts(HttpServletRequest request) {
381+
try {
382+
PlatformClient platformClient = (PlatformClient) request.getAttribute("platformClient");
383+
Extension extension = (Extension) request.getAttribute("extension");
384+
WebhookService webhookService = extension.getWebhookService();
385+
webhookService.enableSalesChannelWebhook(platformClient,"66e3b32eca4335d0feff486c");
386+
return "Webhook enabled successfully!";
387+
} catch (Exception e) {
388+
System.out.println(e.getMessage());
389+
throw new RuntimeException(e);
390+
}
391+
392+
}
393+
}
394+
395+
```
396+
397+
#### How to register for Webhook Events?
398+
399+
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.
400+
401+
```yaml
402+
ext :
403+
api_key : <API_KEY>
404+
api_secret : <API_SECRET>
405+
scope : ""
406+
base_url : "https://test.extension.com"
407+
access_mode : "offline"
408+
webhook:
409+
api_path: "/webhook" #<POST API URL>
410+
notification_email: <EMAIL_ID>
411+
subscribe_on_install: false, #optional. Default true
412+
subscribed_saleschannel: 'specific' #Optional. Default all
413+
marketplace: true, # to receive marketplace saleschannel events. Only allowed when subscribed_saleschannel is set to specific
414+
event_map:
415+
- name: 'product/update'
416+
handler: productCreateHandler #Make sure this matches the Component Bean name
417+
category: 'company'
418+
version: 1
419+
filters:
420+
query: "$.brand.uid"
421+
condition: "(uid) => uid === 130"
422+
reducer:
423+
brand_name: "$.brand.name"
424+
```
425+
345426
##### How webhook registry subscribes to webhooks on Fynd Platform?
346427
347428
After webhook config is passed to initialize 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.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010
<groupId>com.fynd</groupId>
1111
<artifactId>fynd-extension-java</artifactId>
12-
<version>0.6.6</version>
12+
<version>0.6.7</version>
1313
<name>fynd-extension-java</name>
1414
<description>Java Fynd Extension Library</description>
1515
<properties>

src/main/java/com/fynd/extension/middleware/PlatformClientCall.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
import com.fynd.extension.model.webhookmodel.SubscriberConfig;
44
import com.fynd.extension.model.webhookmodel.SubscriberConfigList;
55
import com.fynd.extension.model.webhookmodel.SubscriberConfigRequestV2;
6+
import com.fynd.extension.model.webhookmodel.SubscriberConfigRequestV3;
67
import com.fynd.extension.model.webhookmodel.SubscriberConfigResponse;
8+
import com.fynd.extension.model.webhookmodel.SubscriberConfigResponseV3;
79

810
import retrofit2.Call;
911
import retrofit2.http.*;
1012

1113
public interface PlatformClientCall {
14+
@PUT("/service/platform/webhook/v3.0/company/{company_id}/subscriber/")
15+
Call<SubscriberConfigResponseV3> registerSubscriberToEventV3(@Path("company_id") String companyId, @Body SubscriberConfigRequestV3 payload);
16+
1217
@POST("/service/platform/webhook/v2.0/company/{company_id}/subscriber/")
1318
Call<SubscriberConfigResponse> registerSubscriberToEventV2(@Path("company_id") String companyId, @Body SubscriberConfigRequestV2 payload);
1419

@@ -23,5 +28,5 @@ public interface PlatformClientCall {
2328

2429
@PUT ("/service/platform/webhook/v1.0/company/{company_id}/subscriber/")
2530
Call<SubscriberConfigResponse> updateSubscriberConfig(@Path("company_id") String companyId, @Body SubscriberConfig payload);
26-
31+
2732
}

src/main/java/com/fynd/extension/model/EventMapProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import lombok.Getter;
44
import lombok.Setter;
55

6+
import java.util.Map;
7+
68
@Getter
79
@Setter
810
public class EventMapProperties {
@@ -19,4 +21,16 @@ public class EventMapProperties {
1921

2022
private String topic;
2123

24+
private String queue;
25+
26+
private String workflowName;
27+
28+
private String accountId;
29+
30+
private String eventBridgeName;
31+
32+
private Map<String, Object> filters;
33+
34+
private Map<String, Object> reducer;
35+
2236
}

src/main/java/com/fynd/extension/model/WebhookProperties.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class WebhookProperties {
2020

2121
private Boolean subscribeOnInstall;
2222

23+
private Boolean marketplace;
24+
2325
public String getSubscribedSalesChannel() {
2426
return subscribedSalesChannel;
2527
}

src/main/java/com/fynd/extension/model/webhookmodel/Association.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,16 @@
2020
@JsonInclude(JsonInclude.Include.NON_NULL)
2121
public class Association{
2222

23-
24-
25-
26-
27-
28-
2923
@JsonProperty("company_id")
3024
private Integer companyId;
3125

32-
33-
34-
3526
@JsonProperty("application_id")
3627
private List<String> applicationId;
3728

38-
39-
40-
4129
@JsonProperty("extension_id")
4230
private String extensionId;
4331

44-
45-
46-
4732
@JsonProperty("criteria")
4833
private String criteria;
4934

50-
51-
5235
}

src/main/java/com/fynd/extension/model/webhookmodel/BroadcasterConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ public class BroadcasterConfig {
3030

3131
@JsonProperty("created_on")
3232
private String createdOn;
33-
}
33+
}

src/main/java/com/fynd/extension/model/webhookmodel/EventConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public class EventConfig{
8383

8484

8585

86-
8786
@JsonProperty("created_on")
8887
private String createdOn;
8988

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fynd.extension.model.webhookmodel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
import lombok.Setter;
10+
11+
import java.util.List;
12+
13+
@AllArgsConstructor
14+
@NoArgsConstructor
15+
@Getter
16+
@Setter
17+
@JsonIgnoreProperties(ignoreUnknown = true)
18+
@JsonInclude(JsonInclude.Include.NON_NULL)
19+
public class EventMap {
20+
@JsonProperty("webhook_url")
21+
private String webhookUrl;
22+
23+
@JsonProperty("type")
24+
private String type;
25+
26+
@JsonProperty("auth_meta")
27+
private AuthMeta authMeta;
28+
29+
@JsonProperty("events")
30+
private List<EventV3> events;
31+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.fynd.extension.model.webhookmodel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
import lombok.Setter;
10+
11+
import java.util.Map;
12+
13+
@AllArgsConstructor
14+
@NoArgsConstructor
15+
@Getter
16+
@Setter
17+
@JsonIgnoreProperties(ignoreUnknown = true)
18+
@JsonInclude(JsonInclude.Include.NON_NULL)
19+
public class EventV3 {
20+
21+
@JsonProperty("event_category")
22+
private String eventCategory;
23+
24+
@JsonProperty("event_name")
25+
private String eventName;
26+
27+
@JsonProperty("event_type")
28+
private String eventType;
29+
30+
@JsonProperty("version")
31+
private String version;
32+
33+
@JsonProperty("topic")
34+
private String topic;
35+
36+
@JsonProperty("queue")
37+
private String queue;
38+
39+
@JsonProperty("workflow_name")
40+
private String workflowName;
41+
42+
@JsonProperty("event_bridge_name")
43+
private String eventBridgeName;
44+
45+
@JsonProperty("filters")
46+
private Map<String, Object> filters;
47+
48+
@JsonProperty("reducer")
49+
private Map<String, Object> reducer;
50+
51+
}

0 commit comments

Comments
 (0)