Skip to content

Commit 8bd0847

Browse files
author
Bharath Raja
authored
Code styling fixes (#26)
* Fix: all strings to use single quotes https://github.com/airbnb/javascript\?tab\=readme-ov-file\#strings from Airbnb style guide. We can choose double but we need to be consistent * Fix: object property direct access * Fix: formatting spaces and consistent semicolons
1 parent cedce0f commit 8bd0847

File tree

7 files changed

+52
-53
lines changed

7 files changed

+52
-53
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
require("dotenv").config();
4-
const app = require("./server");
3+
require('dotenv').config();
4+
const app = require('./server');
55
const port = process.env.BACKEND_PORT || 8080;
66

77
app.listen(port, () => {
8-
console.log(`Example app listening at http://localhost:${port}`)
9-
});
8+
console.log(`Example app listening at http://localhost:${port}`);
9+
});

jest.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ module.exports = {
2121
'!**/test/**',
2222
'!**/jest.config.js',
2323
'!**/index.js',
24-
"!**/coverage/**",
25-
"!**/coverage_output.js/**",
26-
"!**/coverage_output.json/**",
27-
"!**/start-dev.js"
24+
'!**/coverage/**',
25+
'!**/coverage_output.js/**',
26+
'!**/coverage_output.json/**',
27+
'!**/start-dev.js'
2828
],
2929
bail: true
30-
};
30+
};

jest.init.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
const express = require('express');
2-
jest.mock("@gofynd/fdk-extension-javascript/express/storage", () => {
2+
jest.mock('@gofynd/fdk-extension-javascript/express/storage', () => {
33
return {
4-
SQLiteStorage: jest.fn().mockImplementation(() => ({})),
4+
SQLiteStorage: jest.fn().mockImplementation(() => ({})),
55
};
6-
});
6+
});
77
// Write your own jest init
8-
jest.mock("@gofynd/fdk-extension-javascript/express", jest.fn(() => {
8+
jest.mock('@gofynd/fdk-extension-javascript/express', jest.fn(() => {
99
return {
1010
setupFdk: function () {
1111
return {
1212
fdkHandler: (req, res, next) => {
1313
next();
1414
},
1515
platformApiRoutes: express.Router()
16-
}
16+
};
1717
}
18-
}
19-
}))
18+
};
19+
}));

server.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
const express = require('express');
22
const cookieParser = require('cookie-parser');
33
const bodyParser = require('body-parser');
4-
const path = require("path");
4+
const path = require('path');
55
const sqlite3 = require('sqlite3').verbose();
6-
const serveStatic = require("serve-static");
6+
const serveStatic = require('serve-static');
77
const { 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');
1010
const sqliteInstance = new sqlite3.Database('session_storage.db');
1111
const productRouter = express.Router();
1212

13-
1413
const 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({
4746
const STATIC_PATH = process.env.NODE_ENV === 'production'
4847
? path.join(process.cwd(), 'frontend', 'public', 'dist')
4948
: path.join(process.cwd(), 'frontend');
50-
49+
5150
const app = express();
5251
const 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
5857
app.use(bodyParser.json({
@@ -63,26 +62,26 @@ app.use(bodyParser.json({
6362
app.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

8079
productRouter.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.
107106
platformApiRoutes.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
111110
app.use('/api', platformApiRoutes);
112111

113112
// Serve the Vue app for all other routes
114113
app.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

121120
module.exports = app;

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('Test server', () => {
66
process.env.PORT = mockPort;
77
const app = server();
88
app.listen = jest.fn();
9-
app.listen(mockPort, () => {});
9+
app.listen(mockPort, () => { });
1010
expect(app.listen).toHaveBeenCalledWith(mockPort, expect.any(Function));
1111
});
12-
});
12+
});

test/products.route.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Product Routes', () => {
2020

2121
it('GET /*: Fallback route', async () => {
2222
const res = await request.get('/test');
23-
expect(res.headers['content-type']).toContain("text/html");
23+
expect(res.headers['content-type']).toContain('text/html');
2424
});
2525

2626
it('GET /api/products: should handle errors in the product list route', async () => {

test/utils/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ module.exports = () => {
3838
if (!request) {
3939
request = supertest(createTestApp());
4040
}
41-
return { request, mockPlatformClient }
42-
}
41+
return { request, mockPlatformClient };
42+
};

0 commit comments

Comments
 (0)