11const express = require ( 'express' ) ;
22const cookieParser = require ( 'cookie-parser' ) ;
33const bodyParser = require ( 'body-parser' ) ;
4- const path = require ( " path" ) ;
4+ const path = require ( ' path' ) ;
55const sqlite3 = require ( 'sqlite3' ) . verbose ( ) ;
6- const serveStatic = require ( " serve-static" ) ;
6+ const serveStatic = require ( ' serve-static' ) ;
77const { readFileSync } = require ( 'fs' ) ;
8- const { setupFdk } = require ( " @gofynd/fdk-extension-javascript/express" ) ;
9- const { SQLiteStorage } = require ( " @gofynd/fdk-extension-javascript/express/storage" ) ;
8+ const { setupFdk } = require ( ' @gofynd/fdk-extension-javascript/express' ) ;
9+ const { SQLiteStorage } = require ( ' @gofynd/fdk-extension-javascript/express/storage' ) ;
1010const sqliteInstance = new sqlite3 . Database ( 'session_storage.db' ) ;
1111const productRouter = express . Router ( ) ;
1212
13-
1413const fdkExtension = setupFdk ( {
1514 api_key : process . env . EXTENSION_API_KEY ,
1615 api_secret : process . env . EXTENSION_API_SECRET ,
@@ -20,25 +19,25 @@ const fdkExtension = setupFdk({
2019 auth : async ( req ) => {
2120 // Write you code here to return initial launch url after auth process complete
2221 if ( req . query . application_id )
23- return `${ req . extension . base_url } /company/${ req . query [ ' company_id' ] } /application/${ req . query . application_id } ` ;
22+ return `${ req . extension . base_url } /company/${ req . query . company_id } /application/${ req . query . application_id } ` ;
2423 else
25- return `${ req . extension . base_url } /company/${ req . query [ ' company_id' ] } ` ;
24+ return `${ req . extension . base_url } /company/${ req . query . company_id } ` ;
2625 } ,
27-
26+
2827 uninstall : async ( req ) => {
2928 // Write your code here to cleanup data related to extension
3029 // If task is time taking then process it async on other process.
3130 }
3231 } ,
33- storage : new SQLiteStorage ( sqliteInstance , "exapmple -fynd-platform-extension" ) , // add your prefix
34- access_mode : " online" ,
32+ storage : new SQLiteStorage ( sqliteInstance , 'example -fynd-platform-extension' ) , // add your prefix
33+ access_mode : ' online' ,
3534 webhook_config : {
36- api_path : " /api/webhook-events" ,
37- notification_email : " useremail@example.com" ,
35+ api_path : ' /api/webhook-events' ,
36+ notification_email : ' useremail@example.com' ,
3837 event_map : {
39- " company/product/delete" : {
40- " handler" : ( eventName ) => { console . log ( eventName ) } ,
41- " version" : '1'
38+ ' company/product/delete' : {
39+ ' handler' : ( eventName ) => { console . log ( eventName ) ; } ,
40+ ' version' : '1'
4241 }
4342 }
4443 } ,
@@ -47,12 +46,12 @@ const fdkExtension = setupFdk({
4746const STATIC_PATH = process . env . NODE_ENV === 'production'
4847 ? path . join ( process . cwd ( ) , 'frontend' , 'public' , 'dist' )
4948 : path . join ( process . cwd ( ) , 'frontend' ) ;
50-
49+
5150const app = express ( ) ;
5251const platformApiRoutes = fdkExtension . platformApiRoutes ;
5352
5453// Middleware to parse cookies with a secret key
55- app . use ( cookieParser ( " ext.session" ) ) ;
54+ app . use ( cookieParser ( ' ext.session' ) ) ;
5655
5756// Middleware to parse JSON bodies with a size limit of 2mb
5857app . use ( bodyParser . json ( {
@@ -63,26 +62,26 @@ app.use(bodyParser.json({
6362app . use ( serveStatic ( STATIC_PATH , { index : false } ) ) ;
6463
6564// FDK extension handler and API routes (extension launch routes)
66- app . use ( "/" , fdkExtension . fdkHandler ) ;
65+ app . use ( '/' , fdkExtension . fdkHandler ) ;
6766
6867// Route to handle webhook events and process it.
69- app . post ( '/api/webhook-events' , async function ( req , res ) {
68+ app . post ( '/api/webhook-events' , async function ( req , res ) {
7069 try {
71- console . log ( `Webhook Event: ${ req . body . event } received` )
72- await fdkExtension . webhookRegistry . processWebhook ( req ) ;
73- return res . status ( 200 ) . json ( { " success" : true } ) ;
74- } catch ( err ) {
75- console . log ( `Error Processing ${ req . body . event } Webhook` ) ;
76- return res . status ( 500 ) . json ( { " success" : false } ) ;
70+ console . log ( `Webhook Event: ${ req . body . event } received` ) ;
71+ await fdkExtension . webhookRegistry . processWebhook ( req ) ;
72+ return res . status ( 200 ) . json ( { ' success' : true } ) ;
73+ } catch ( err ) {
74+ console . log ( `Error Processing ${ req . body . event } Webhook` ) ;
75+ return res . status ( 500 ) . json ( { ' success' : false } ) ;
7776 }
78- } )
77+ } ) ;
7978
8079productRouter . get ( '/' , async function view ( req , res , next ) {
8180 try {
8281 const {
8382 platformClient
8483 } = req ;
85- const data = await platformClient . catalog . getProducts ( )
84+ const data = await platformClient . catalog . getProducts ( ) ;
8685 return res . json ( data ) ;
8786 } catch ( err ) {
8887 next ( err ) ;
@@ -96,7 +95,7 @@ productRouter.get('/application/:application_id', async function view(req, res,
9695 platformClient
9796 } = req ;
9897 const { application_id } = req . params ;
99- const data = await platformClient . application ( application_id ) . catalog . getAppProducts ( )
98+ const data = await platformClient . application ( application_id ) . catalog . getAppProducts ( ) ;
10099 return res . json ( data ) ;
101100 } catch ( err ) {
102101 next ( err ) ;
@@ -106,16 +105,16 @@ productRouter.get('/application/:application_id', async function view(req, res,
106105// FDK extension api route which has auth middleware and FDK client instance attached to it.
107106platformApiRoutes . use ( '/products' , productRouter ) ;
108107
109- // If you are adding routes outside of the /api path,
108+ // If you are adding routes outside of the /api path,
110109// remember to also add a proxy rule for them in /frontend/vite.config.js
111110app . use ( '/api' , platformApiRoutes ) ;
112111
113112// Serve the Vue app for all other routes
114113app . get ( '*' , ( req , res ) => {
115114 return res
116- . status ( 200 )
117- . set ( " Content-Type" , " text/html" )
118- . send ( readFileSync ( path . join ( STATIC_PATH , " index.html" ) ) ) ;
115+ . status ( 200 )
116+ . set ( ' Content-Type' , ' text/html' )
117+ . send ( readFileSync ( path . join ( STATIC_PATH , ' index.html' ) ) ) ;
119118} ) ;
120119
121120module . exports = app ;
0 commit comments