-
Notifications
You must be signed in to change notification settings - Fork 89
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
Adding AS types & grant requests support to open-payments client #727
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5ae5f3f
feat(open-payments): adding AS types
mkurapov deb3081
feat(open-payments): adding support for grant requests
mkurapov 9b1b87a
Merge branch 'main' into 633/mk/adding-AS-types-to-client
mkurapov 17af881
chore(open-payments): update open-payments spec commit version
mkurapov ac71e7c
chore(open-payments): update AS request/response types
mkurapov f0febf0
chore(open-payments): rename AS generated types file
mkurapov 5aa5370
chore(open-payments): merge bw-httpsig
mkurapov ca946c8
chore(open-payments): update types, fix tests
mkurapov 94f95e5
Merge branch 'main' into 633/mk/adding-AS-types-to-client
mkurapov 0a453d5
chore(open-payments): update open api specs
mkurapov 6eff96c
feat(open-payments): update grant request
mkurapov b219aef
feat(open-payments) adding tests for new grant fetching methods
mkurapov 4252c8e
Merge branch 'main' into 633/mk/adding-AS-types-to-client
mkurapov 7b6407f
chore(open-payments): rename dependency var
mkurapov 86304fe
feat(open-payments): unify the grant request call
mkurapov f8154ba
chore(open-payments): simplify type
mkurapov 1e5a71a
feat(open-payments): move around type guards
mkurapov d9d7f7d
chore(open-payments): remove duplicate fns
mkurapov d2c0295
feat(open-payments): address comments
mkurapov 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,28 @@ | ||
import { createGrantRoutes } from './grant' | ||
import { OpenAPI, HttpMethod, createOpenAPI } from 'openapi' | ||
import config from '../config' | ||
import { defaultAxiosInstance, silentLogger } from '../test/helpers' | ||
|
||
describe('grant', (): void => { | ||
let openApi: OpenAPI | ||
|
||
beforeAll(async () => { | ||
openApi = await createOpenAPI(config.OPEN_PAYMENTS_AS_OPEN_API_URL) | ||
}) | ||
|
||
const axiosInstance = defaultAxiosInstance | ||
const logger = silentLogger | ||
|
||
describe('createGrantRoutes', (): void => { | ||
test('creates response validator for grant requests', async (): Promise<void> => { | ||
jest.spyOn(openApi, 'createResponseValidator') | ||
|
||
createGrantRoutes({ axiosInstance, openApi, logger }) | ||
expect(openApi.createResponseValidator).toHaveBeenCalledTimes(1) | ||
expect(openApi.createResponseValidator).toHaveBeenCalledWith({ | ||
path: '/', | ||
method: HttpMethod.POST | ||
}) | ||
}) | ||
}) | ||
}) |
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,41 @@ | ||
import { HttpMethod } from 'openapi' | ||
import { RouteDeps } from '.' | ||
import { | ||
getASPath, | ||
InteractiveGrant, | ||
NonInteractiveGrant, | ||
GrantRequest | ||
} from '../types' | ||
import { post } from './requests' | ||
|
||
interface RequestGrantArgs { | ||
url: string | ||
request: GrantRequest | ||
} | ||
|
||
export interface GrantRoutes { | ||
requestGrant( | ||
args: RequestGrantArgs | ||
): Promise<InteractiveGrant | NonInteractiveGrant> | ||
} | ||
|
||
export const createGrantRoutes = (deps: RouteDeps): GrantRoutes => { | ||
const requestGrantValidator = deps.openApi.createResponseValidator< | ||
InteractiveGrant | NonInteractiveGrant | ||
>({ | ||
path: getASPath('/'), | ||
method: HttpMethod.POST | ||
}) | ||
return { | ||
requestGrant: (args: RequestGrantArgs) => | ||
post(deps, { url: args.url, body: args.request }, requestGrantValidator) | ||
} | ||
} | ||
|
||
export const isInteractiveGrant = ( | ||
grant: InteractiveGrant | NonInteractiveGrant | ||
): grant is InteractiveGrant => !!(grant as InteractiveGrant).interact | ||
|
||
export const isNonInteractiveGrant = ( | ||
grant: InteractiveGrant | NonInteractiveGrant | ||
): grant is NonInteractiveGrant => !!(grant as NonInteractiveGrant).access_token |
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
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
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.
or
https://datatracker.ietf.org/doc/html/draft-ietf-gnap-core-protocol#section-2
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.
yup, had
request
in my follow-up PR, will do it here instead