Skip to content

Commit

Permalink
Merge pull request #56 from gofynd/remove-register-webhook-call-if-no…
Browse files Browse the repository at this point in the history
…-events-added-for-provider

Remove register webhook call if no events added for provider
  • Loading branch information
brijeshgajjarfynd authored Jul 12, 2024
2 parents 5e2e3f7 + e7b6838 commit d962cca
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
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.6] - 2024-07-11
### Changed
- Exported `apiRoutes` as `platformApiRoutes`. The `apiRoutes` export will be deprecated in the next major release.
- Optimized webhook subscription by reducing unnecessary API calls.

---
## [v0.7.5] - 2024-06-19
### Changed
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ let fdkClient = setupFdk({
api_secret: "<API_SECRET>",
base_url: baseUrl, // this is optional
scopes: ["company/products"], // this is optional
callbacks: extensionHandler,
callbacks: {
auth: async function (data) {
console.log("called auth callback");
},
uninstall: async function (data) {
console.log("called uninstall callback");
},
},
storage: new RedisStorage(redis),
access_mode: "offline",
webhook_config: {
Expand All @@ -133,7 +140,7 @@ let fdkClient = setupFdk({
},
'application/coupon/create': {
version: '1',
topic: 'coupon_create_kafka_topic'
topic: 'coupon_create_kafka_topic',
provider: 'kafka'
}
}
Expand Down
3 changes: 2 additions & 1 deletion express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function setupFdk(data, syncInitialization) {
throw err;
});
let router = setupRoutes(extension);
let { apiRoutes, applicationProxyRoutes, partnerApiRoutes } = setupProxyRoutes(data);
let { apiRoutes, platformApiRoutes, applicationProxyRoutes, partnerApiRoutes } = setupProxyRoutes(data);

async function getPlatformClient(companyId) {
let client = null;
Expand Down Expand Up @@ -48,6 +48,7 @@ function setupFdk(data, syncInitialization) {
fdkHandler: router,
extension: extension,
apiRoutes: apiRoutes,
platformApiRoutes: platformApiRoutes,
partnerApiRoutes: partnerApiRoutes,
webhookRegistry: extension.webhookRegistry,
applicationProxyRoutes: applicationProxyRoutes,
Expand Down
11 changes: 11 additions & 0 deletions express/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const hmacSHA256 = require("crypto-js/hmac-sha256");
const { fdkAxios } = require("@gofynd/fdk-client-javascript/sdk/common/AxiosHelper");
const { version } = require('./../package.json');
const { TEST_WEBHOOK_EVENT_NAME, ASSOCIATION_CRITERIA } = require("./constants");
const { FdkWebhookProcessError, FdkWebhookHandlerNotFound, FdkWebhookRegistrationError, FdkInvalidHMacError, FdkInvalidWebhookConfig } = require("./error_code");
const logger = require("./logger");
Expand Down Expand Up @@ -236,6 +237,10 @@ class WebhookRegistry {

try {
if (registerNew) {
if(subscriberConfig.events.length == 0){
logger.debug(`Skipped registerSubscriber API call as no ${configType} based events found`);
return;
}
await this.registerSubscriberConfig(platformClient, subscriberConfig);
if (this._fdkConfig.debug) {
subscriberConfig.events = subscriberConfig.events.map(event => event.slug);
Expand Down Expand Up @@ -412,6 +417,7 @@ class WebhookRegistry {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
"x-ext-lib-version": `js/${version}`
}
}
return await fdkAxios.request(rawRequest);
Expand Down Expand Up @@ -441,6 +447,7 @@ class WebhookRegistry {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
"x-ext-lib-version": `js/${version}`
}
}
const response = await fdkAxios.request(rawRequest);
Expand Down Expand Up @@ -486,6 +493,7 @@ class WebhookRegistry {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
"x-ext-lib-version": `js/${version}`
}
}
return await fdkAxios.request(rawRequest);
Expand Down Expand Up @@ -514,6 +522,7 @@ class WebhookRegistry {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
"x-ext-lib-version": `js/${version}`
}
}
const response = await fdkAxios.request(rawRequest);
Expand Down Expand Up @@ -552,6 +561,7 @@ class WebhookRegistry {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
"x-ext-lib-version": `js/${version}`
}
}
const subscriberConfigResponse = await fdkAxios.request(rawRequest);
Expand Down Expand Up @@ -611,6 +621,7 @@ class WebhookRegistry {
data: data,
headers: {
"Content-Type": "application/json",
"x-ext-lib-version": `js/${version}`
},
};
let responseData = await fdkAxios.request(rawRequest);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"name": "@gofynd/fdk-extension-javascript",
"description": "FDK Extension Helper Library",
"version": "0.7.5",
"version": "0.7.6",
"main": "index.js",
"directories": {
"example": "examples"
Expand Down

0 comments on commit d962cca

Please sign in to comment.