Skip to content

Commit

Permalink
feat: Adding ESlint To Platform OAuth (picahq#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth-bhansali authored Sep 3, 2024
1 parent dd5a597 commit 661d6cd
Show file tree
Hide file tree
Showing 37 changed files with 1,325 additions and 1,211 deletions.
6 changes: 6 additions & 0 deletions integrationos-oauth/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
build
# don't lint nyc coverage output
coverage
33 changes: 33 additions & 0 deletions integrationos-oauth/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier",
"jest"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"no-console": [
"error",
{
"allow": [
"log",
"warn",
"error"
]
}
],
"@typescript-eslint/no-var-requires": "warn",
"prettier/prettier": 2
},
"env": {
"browser": true,
"node": true,
"jest/globals": true
}
}
6 changes: 6 additions & 0 deletions integrationos-oauth/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 4
}
63 changes: 40 additions & 23 deletions integrationos-oauth/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
{
"name": "platform-oauth",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/index.ts",
"build": "tsc"
},
"author": "@integrationos",
"license": "ISC",
"description": "",
"dependencies": {
"axios": "^1.7.2",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.6",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
"name": "platform-oauth",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/index.ts",
"build": "tsc",
"lint": "eslint . --ext .ts",
"lint-fix": "eslint . --ext .ts --fix",
"prettier-format": "run-script-os",
"prettier-format:win32": "prettier --config .prettierrc \"./src/**/*.ts\" --write",
"prettier-format:darwin:linux": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-format:default": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-watch": "run-script-os",
"prettier-watch:win32": "onchange \"src/**/*.ts\" -- prettier --write {{changed}}",
"prettier-watch:darwin:linux": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"prettier-watch:default": "onchange 'src/**/*.ts' -- prettier --write {{changed}}"
},
"author": "@integrationos",
"license": "ISC",
"description": "",
"dependencies": {
"axios": "^1.7.2",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.6",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^26.6.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1"
}
}
76 changes: 38 additions & 38 deletions integrationos-oauth/src/connections/attio/init.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import axios from "axios";
import qs from "qs";
import { DataObject, OAuthResponse } from "../../lib/types";
import axios from 'axios';
import qs from 'qs';
import { DataObject, OAuthResponse } from '../../lib/types';

export const init = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const {
clientId,
clientSecret,
metadata: { code },
} = body;
try {
const {
clientId,
clientSecret,
metadata: { code },
} = body;

const baseUrl = `https://app.attio.com/oauth`;
const baseUrl = `https://app.attio.com/oauth`;

const requestBody = {
grant_type: "authorization_code",
code: code,
client_id: clientId,
client_secret: clientSecret,
};
const requestBody = {
grant_type: 'authorization_code',
code: code,
client_id: clientId,
client_secret: clientSecret,
};

const response = await axios({
url: `${baseUrl}/token`,
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
},
data: qs.stringify(requestBody),
});
const response = await axios({
url: `${baseUrl}/token`,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
},
data: qs.stringify(requestBody),
});

const {
data: { access_token: accessToken, token_type: tokenType },
} = response;
const {
data: { access_token: accessToken, token_type: tokenType },
} = response;

return {
accessToken,
refreshToken: accessToken,
expiresIn: 2147483647,
tokenType,
meta: {},
};
} catch (error) {
throw new Error(`Error fetching access token for Attio: ${error}`);
}
return {
accessToken,
refreshToken: accessToken,
expiresIn: 2147483647,
tokenType,
meta: {},
};
} catch (error) {
throw new Error(`Error fetching access token for Attio: ${error}`);
}
};
30 changes: 15 additions & 15 deletions integrationos-oauth/src/connections/attio/refresh.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { DataObject, OAuthResponse } from "../../lib/types";
import { DataObject, OAuthResponse } from '../../lib/types';

export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const {
OAUTH_METADATA: { accessToken, refreshToken, tokenType, meta },
} = body;
return {
accessToken,
refreshToken,
expiresIn: 2147483647,
tokenType,
meta,
};
} catch (error) {
throw new Error(`Error fetching refresh token for Attio: ${error}`);
}
try {
const {
OAUTH_METADATA: { accessToken, refreshToken, tokenType, meta },
} = body;
return {
accessToken,
refreshToken,
expiresIn: 2147483647,
tokenType,
meta,
};
} catch (error) {
throw new Error(`Error fetching refresh token for Attio: ${error}`);
}
};
24 changes: 15 additions & 9 deletions integrationos-oauth/src/connections/clover/init.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import axios from "axios";
import axios from 'axios';

import { DataObject, OAuthResponse } from "../../lib/types";
import { DataObject, OAuthResponse } from '../../lib/types';

export const init = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const requestBody = {
grant_type: "authorization_code",
grant_type: 'authorization_code',
code: body.metadata?.code,
client_id: body.clientId,
client_secret: body.clientSecret,
};

const baseUrl = body.metadata?.environment === "live" ? "https://api.clover.com" : "https://sandbox.dev.clover.com";
const baseUrl =
body.metadata?.environment === 'live'
? 'https://api.clover.com'
: 'https://sandbox.dev.clover.com';

const response = await axios.post(`${baseUrl}/oauth/token`, requestBody);
const response = await axios.post(
`${baseUrl}/oauth/token`,
requestBody,
);

const accessToken = response.data?.access_token;

return {
accessToken,
refreshToken: accessToken,
expiresIn: 2147483647,
tokenType: "Bearer",
tokenType: 'Bearer',
meta: {
merchantId: body.metadata?.additionalData?.merchant_id,
employeeId: body.metadata?.additionalData?.employee_id,
baseUrl
}
baseUrl,
},
};
} catch (error) {
throw new Error(`Error fetching access token for Clover: ${error}`);
}
};
};
4 changes: 2 additions & 2 deletions integrationos-oauth/src/connections/clover/refresh.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { OAuthResponse } from "../../lib/types";
import { OAuthResponse } from '../../lib/types';

export const refresh = async (payload: any): Promise<OAuthResponse> => {
return {
accessToken: payload.accessToken,
refreshToken: payload.refreshToken,
expiresIn: payload.expiresIn,
tokenType: payload.tokenType,
meta: payload.meta
meta: payload.meta,
};
};
Loading

0 comments on commit 661d6cd

Please sign in to comment.