forked from picahq/pica
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding ESlint To Platform OAuth (picahq#138)
- Loading branch information
1 parent
dd5a597
commit 661d6cd
Showing
37 changed files
with
1,325 additions
and
1,211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"tabWidth": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
Oops, something went wrong.