-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(openIntProxyLink): Adding Openint proxy link #39
Merged
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
12d4e43
adding openIntProxyLink
pellicceama 8340ea4
migratinng sdk-qbo to new auth paradigm
pellicceama 4feb3cf
adding qbo proxy spec
pellicceama 00f37c1
migrating apollo
pellicceama 02d314a
adding authHeadersLink
pellicceama 5e03a24
lints in proxyLink
pellicceama f34d9ad
supporting new auth parameter paradigm
pellicceama e20fed1
adding new authLink
pellicceama 4434f24
qbo proxy tests
pellicceama 9e79f96
lint
pellicceama 9fbcc5a
fix: some pr review changes
tonyxiao 1356b24
fix: type error
tonyxiao 2787124
fix: type error
tonyxiao bc25c89
fix: test
tonyxiao 01ebc72
fixing circular dependency
pellicceama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,88 @@ | ||
import {Link} from '../link.js' | ||
import {mergeHeaders, modifyRequest} from '../modifyRequestResponse.js' | ||
|
||
interface OpenIntProxyHeaders { | ||
authorization?: `Bearer ${string}` | ||
'x-apikey'?: string | ||
'x-resource-id': string | ||
} | ||
|
||
export type OpenIntProxyLinkOptions = { | ||
token?: string | ||
apiKey?: string | ||
resourceId?: string | ||
endUserId?: string | ||
connectorName?: string | ||
} | ||
|
||
export function validateOpenIntProxyLinkOptions( | ||
options: OpenIntProxyLinkOptions, | ||
): boolean { | ||
const {token, apiKey, resourceId, endUserId, connectorName} = options ?? {} | ||
|
||
const hasToken = !!token | ||
const hasApiKey = !!apiKey | ||
const hasResourceId = !!resourceId | ||
const hasEndUserId = !!endUserId | ||
const hasConnectorName = !!connectorName | ||
|
||
const expectsAuthProxy = | ||
hasToken || hasApiKey || hasResourceId || hasEndUserId || hasConnectorName | ||
if ( | ||
expectsAuthProxy && | ||
!( | ||
(hasToken && hasResourceId) || | ||
(hasToken && hasConnectorName) || | ||
(hasApiKey && hasResourceId) || | ||
(hasApiKey && hasEndUserId && hasConnectorName) | ||
) | ||
) { | ||
throw new Error( | ||
'Invalid configuration for proxy authentication. You must provide one of the following combinations: ' + | ||
'1) token AND resourceId, ' + | ||
'2) token AND connectorName, ' + | ||
'3) apiKey AND resourceId, ' + | ||
'4) apiKey AND endUserId AND connectorName, ' + | ||
'or none of these options and instead authenticate directly.', | ||
) | ||
} | ||
return expectsAuthProxy | ||
} | ||
|
||
interface OpenIntProxyHeaders { | ||
authorization?: `Bearer ${string}` | ||
'x-apikey'?: string | ||
'x-resource-id': string | ||
'x-resource-end-user-id'?: string | ||
'x-resource-connector-name'?: string | ||
} | ||
|
||
// TODO: Test that I'm actally working! | ||
export function openIntProxyLink(opts: OpenIntProxyLinkOptions): Link { | ||
validateOpenIntProxyLinkOptions(opts) | ||
const {apiKey, token, resourceId, endUserId, connectorName} = opts | ||
|
||
const headers = { | ||
['x-apikey']: apiKey || token || '', | ||
['x-resource-id']: resourceId || '', | ||
['x-resource-end-user-id']: endUserId || '', | ||
['x-resource-connector-name']: connectorName || '', | ||
} satisfies OpenIntProxyHeaders | ||
|
||
return async (req, next) => { | ||
const baseUrl = getBaseUrl(req.url) | ||
const res = await next( | ||
modifyRequest(req, { | ||
url: req.url.replace(baseUrl, 'https://app.openint.dev/proxy/'), | ||
headers: mergeHeaders(req.headers, headers, {}), | ||
body: req.body, | ||
}), | ||
) | ||
return res | ||
} | ||
} | ||
|
||
function getBaseUrl(urlStr: string) { | ||
const url = new URL(urlStr) | ||
return `${url.protocol}//${url.host}/` | ||
} |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
OpenIntProxyHeaders
interface is defined twice in this file. Consider removing the duplicate definition to avoid confusion.